I am trying to create a function that takes an array input of consecutive characters in the alphabet and returns the missing letter if there is one (there will only be 1 missing letter and each element in the array will be listed in alphabetical order).
Example inputs:
['a', 'b', 'c', 'e'] -> 'd'
['l', 'n', 'o', 'p'] -> 'm'
['s', 't', 'u', 'w', 'x'] -> 'v'
const findMissingLetter = () => {
const stepOne = (array) => {
for (let i = 0; i < array.length; i++) {
let x = array.charCodeAt(i + 1);
let y = array.charCodeAt(i);
if ((x - y) != 1) {
return (array.charCodeAt[i] + 1);
}
}
}
}
return findMissingLetter(stepOne.fromCharCode(array));
What I am attempting to do is loop through each index of the array and convert each character to unicode. If the [i + 1] - [i] elements in the array equal 1, then there is no missing letters. However if it does not equal 1, then I want to return the unicode of [i] + 1 and then through the higher order function convert the unicode output back to the corresponding character in the alphabet.
Can someone please explain what I am doing wrong? I know I am not calling the functions correctly.
Thanks!
I came with this solution:
This will return an array of missing letter(s) between the starting and ending alphabet letter.