https://www.codewars.com/kata/5839edaa6754d6fec10000a2
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
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){
let letter = ''
for(let i = 0; i < array.length - 1; i++){
let num = array[i].charCodeAt() + 1
if(num != array[i + 1].charCodeAt()){
letter = String.fromCharCode(num);
}
}
return letter;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Odd or Even? (7 kyu) / JavaScript (0) | 2023.01.10 |
---|---|
[Codewars] Valid Parentheses (5 kyu) / JavaScript (0) | 2023.01.09 |
[Codewars] Split Strings (6 kyu) / JavaScript (0) | 2023.01.06 |
[Codewars] Find the unique number (6 kyu) / JavaScript (0) | 2023.01.05 |
[Codewars] A Needle in the Haystack (8 kyu) / JavaScript (0) | 2023.01.04 |
댓글