I need to find difference between two strings.
const string1 = \'lebronjames\';
const string2 = \'lebronnjames\';
The expected output is t
this will return the first difference between two string
Like for lebronjames and lebronnjames is n
const string1 = 'lebronjames';
const string2 = 'lebronnjabes';
const findFirstDiff = (str1, str2) =>
str2[[...str1].findIndex((el, index) => el !== str2[index])];
// equivalent of
const findFirstDiff2 = function(str1, str2) {
return str2[[...str1].findIndex(function(el, index) {
return el !== str2[index]
})];
}
console.log(findFirstDiff2(string1, string2));
console.log(findFirstDiff(string1, string2));