Skip to content

Instantly share code, notes, and snippets.

@rupertsworld
Created December 3, 2018 05:56
Show Gist options
  • Save rupertsworld/4710e52dde28d4301c2cce980b670257 to your computer and use it in GitHub Desktop.
Save rupertsworld/4710e52dde28d4301c2cce980b670257 to your computer and use it in GitHub Desktop.
const strings = [
'abcde',
'fghij',
'klmnop',
'klnmpo',
'axcde'
];
const strlen = strings[0].length;
let strIndex1 = 0;
let strIndex2 = 1;
function iter() {
if (strIndex2 === strings.length) {
strings.splice(strIndex1, 1);
strIndex1 = 0;
strIndex2 = 1;
iter();
return;
}
if (strIndex1 === strings.length) {
console.log("No strings found"); return;
}
const str1 = strings[strIndex1];
const str2 = strings[strIndex2];
let matches = 0;
for (j = 0; j < strlen; j++) {
if (str1.charAt(j) !== str2.charAt(j)) {
matches++;
}
}
if (matches === 1) {
console.log("MATCH! " + str1 + " - " + str2);
return;
} else {
console.log("No match! " + str1 + " - " + str2);
strIndex2++;
iter();
return;
}
}
iter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment