Files
typescript-katas/6kyu/find-the-missing-letter/solution.ts
2025-01-31 22:55:24 +01:00

11 lines
539 B
TypeScript

export function findMissingLetter(array: string[]): string {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
// convert array to alphabet index values
const indexes = array.map((char) => alphabet.indexOf(char.toLowerCase()));
// find the missing index
const missingIndex = indexes.find((index, i) => indexes[i + 1] - index > 1) as number;
const isInputUpperCase = array[0] === array[0].toUpperCase();
const missingLetter = alphabet[missingIndex + 1];
return isInputUpperCase ? missingLetter.toUpperCase() : missingLetter;
}