27
2
Guidelines
Task
Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array (lists in some languages).
Rules
- This is code golf so the shortest answer in bytes wins!
- You will always get a valid array
- There will always be exactly one letter missing
- The length of the array will always be at least 2.
- The array will always contain letters in only one case (uppercase or lowercase)
- You must output in the same case (uppercase or lowercase) that the input is
- The array will always only go one letter a time (skipping the missing letter)
- The array length will be between 2 and 25
- The first or last element of the array will never be missing
Examples
['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'
['x','z'] -> 'y'
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z'] -> 'v'
Can I take a string instead? – Leaky Nun – 2017-07-17T07:41:33.013
@LeakyNun Strings are arrays of characters, so yes. – aimorris – 2017-07-17T07:42:54.013
Will the first or the last ever go missing? – Leaky Nun – 2017-07-17T07:46:48.823
@LeakyNun No. I have edited the question to make it clearer. – aimorris – 2017-07-17T07:49:12.560
1Can the output be an array containing the missing character (e.g: for the input
['a','b','c','d','f','g']
, output['e']
, if that makes the code shorter? – Mr. Xcoder – 2017-07-17T08:59:51.5671@Mr.Xcoder A string is just an array of characters, so yes – aimorris – 2017-07-17T09:02:30.443
@rahnema1 Completely different, but okay... – aimorris – 2017-07-17T09:03:25.743
Is a full program that reads from standard input and prints to standard output acceptable? And what about an anonymous code block / lambda function? Or a named stand-alone function, for languages that don't have "methods"? Or even just a code snippet that isn't wrapped in a block / lambda / function / method? (Quite a lot of the answers, including mine at the moment, seem to be of this type. In some languages with implicit I/O, such snippets are effectively indistinguishable from full programs.) – Ilmari Karonen – 2017-07-17T11:30:52.633
2Rule four is simply a subset of rule eight and can be removed (at least, if you put the word "inclusive" at the end of rule eight). – NH. – 2017-07-17T19:13:06.900