Skip to content

Instantly share code, notes, and snippets.

@keepitterron
Created March 20, 2020 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keepitterron/ef525896bfb26a21397623cc097c9399 to your computer and use it in GitHub Desktop.
Save keepitterron/ef525896bfb26a21397623cc097c9399 to your computer and use it in GitHub Desktop.
Find the missing letter in range
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