Created
December 3, 2018 05:56
-
-
Save rupertsworld/4710e52dde28d4301c2cce980b670257 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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