11 lines
539 B
TypeScript
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;
|
|
} |