Skip to content

Instantly share code, notes, and snippets.

@tomanistor
Created June 22, 2017 17:40
Show Gist options
  • Save tomanistor/b10a36cafdb024927c82b3d10ade04a1 to your computer and use it in GitHub Desktop.
Save tomanistor/b10a36cafdb024927c82b3d10ade04a1 to your computer and use it in GitHub Desktop.
Find the missing letter

Find the missing letter

Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.

You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. The array will always contain letters in only one case.

Example:

['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'

(Use the English alphabet with 26 letters!)

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have also created other katas. Take a look if you enjoyed this kata!

function findMissingLetter(array) {
var string = array.join("");
for (var i = 0; i < string.length; i++) {
if (string.charCodeAt(i + 1) - string.charCodeAt(i) != 1) {
return String.fromCharCode(string.charCodeAt(i) + 1);
}
}
}
@Sam-nolimit
Copy link

function findMissingLetter(array)
{
let i=array[0].charCodeAt();
array.map(x=> x.charCodeAt()==i?i++:i);
return String.fromCharCode(i);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment