add kata
This commit is contained in:
18
6kyu/find-the-missing-letter/description.md
Normal file
18
6kyu/find-the-missing-letter/description.md
Normal file
@@ -0,0 +1,18 @@
|
||||
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!
|
||||
11
6kyu/find-the-missing-letter/solution.ts
Normal file
11
6kyu/find-the-missing-letter/solution.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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;
|
||||
}
|
||||
9
6kyu/find-the-missing-letter/tests.ts
Normal file
9
6kyu/find-the-missing-letter/tests.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { findMissingLetter } from './solution';
|
||||
import { assert } from "chai";
|
||||
|
||||
describe("solution", function(){
|
||||
it("exampleTests", function(){
|
||||
assert.equal(findMissingLetter(['a','b','c','d','f']), 'e');
|
||||
assert.equal(findMissingLetter(['O','Q','R','S']), 'P');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user