알고리즘 90 - Find the missing letter

박진현·2021년 7월 24일
0

Q.

#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'

["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!

A)

function findMissingLetter(array)
{
  for (let i = 0; i < array.length; i++) {
    if (array[i].charCodeAt()+1 !== array[i+1].charCodeAt()) 
      return String.fromCharCode(array[i].charCodeAt()+1)
  }
}
profile
👨🏻‍💻 호기심이 많고 에러를 좋아하는 프론트엔드 개발자 박진현 입니다.

0개의 댓글