JSFiddle - React, Tailwind, and code Playground

by JeffC

JavaScript

var string1 = "Give clients and new customers a custom wood business card design. Promote your carpentry, flooring, cabinetry and other businesses with wood business cards. Personalize your business cards with your company name, name, title, phone number and address.";
var string2 = "Give  clients and new customers a custom wood business card design. Promote your carpentry, flooring, cabinetry and other businesses with wood business cards. Personalize your business cards with your company name, name, title, phone number and address.";

function FindDifference(s1, s2)
{
    var index = 0;
    var max = Math.min(s1.length, s2.length);
    while (index < max && s1.charAt(index) === s2.charAt(index))
    {
        index++;
    }
    return ++index;
}

function AsciiString(s1)
{
    var output = "";
    var code = "";
    for (i = 0; i < s1.length; i++)
    {
        code = s1.charCodeAt(i).toString();
        while (code.length < 3)
        {
            code = "0" + code;
        }
        output += code + " ";
    }
    return output;
}

function p(s)
{
    document.writeln(s + "<br>");
}

p(string1);
p(string2);

var index = FindDifference(string1, string2);
p(index);
var start = Math.max(0, index - 5);
var end = Math.min(index + 5, Math.min(string1.length, string2.length));
sub1 = string1.substr(start, end - start);
sub2 = string2.substr(start, end - start);
p(sub1);
p(AsciiString(sub1));
p(AsciiString(sub2));
p(sub2);