JSFiddle - React, Tailwind, and code Playground

by Kevin Faulhaber

JavaScript

var string1 = "The red fox is moving on the hill.";
var string2 = "The black fox is moving in the bill.";


alert(difference(string1, string2));

function difference(str1, str2)
{
    if(str1.length != 0 && str2.length != 0)
    {
     alert(str1 + ' ' + str2);
     var s1 = (typeof str1 === 'string') ? str1.split(" ") : str1;
     var s2 = (typeof str2 === 'string') ? str2.split(" ") : str2;
     var same = 0;
     if(s1[0] === s2[0])
     {
             same = 1;
     }
    }
     return same + difference(s1.splice(1, s1.length-1), s2.splice(1, s2.length-1));
}