Created
March 20, 2020 10:06
-
-
Save keepitterron/ef525896bfb26a21397623cc097c9399 to your computer and use it in GitHub Desktop.
Find the missing letter in range
This file contains 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 = ['abcd', 'cdefg', 'pqrs', 'abde']; | |
const missingLetter = string => { | |
return [...string] | |
.map(ltr => ltr.charCodeAt()) | |
.map((code, index, all) => { | |
const prev = all[index - 1]; | |
const expected = code - 1; | |
if (prev && prev !== expected) { | |
return String.fromCharCode(expected); | |
} | |
}) | |
.filter(Boolean) | |
.pop(); | |
}; | |
console.log(strings.map(missingLetter)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment