25
2
Given a non-empty string consisting of only lower and upper case alphabetical characters and spaces ([a-zA-Z ]
), reduce it to a snippet of the alphabet, starting with the first character.
To reduce a string, begin with the first alphabetical character, then remove every character after it that is not the next letter of the alphabet. Continue doing this until you reach the end of the string.
For example codegolf
:
Begin with c
, remove o
as it is not the next letter of the alphabet.
Keep d
as it is the next letter of the alphabet, and keep e
as it is the next letter too.
Remove g
, o
, and l
, and keep f
.
Your final snippet would then be cdef
Rules
- Capitalisation should be maintained, so
CodEgolF
would result inCdEF
- Space is not a letter of the alphabet, and thus should always be removed, even if it is the start of the string
- Due to the nature of the reduction, the first alphabetical character of the input will always be the first character of the output.
zZ
is the last letter of the alphabet. There are no letters after it, the alphabet does not loop.
Test Cases
codegolf -> cdef
CodEgolf -> CdEf
codeolfg -> cdefg
ProgrammingPuzzles -> P
Stack Exchange -> St
The quick red fox jumped over the lazy brown dog -> Tuvw
Zebra -> Z
Abcdegfhijkl -> Abcdef
Scoring
This is code-golf, so fewest bytes in each language wins!
From the second last test case, i see that if we reach
z
We just stop, right? – Mr. Xcoder – 2017-08-17T10:05:10.327@Mr.Xcoder Correct, see the last point under "Rules" – Skidsdev – 2017-08-17T10:08:46.450
2Please add a test case with a space at the beginning. Like:
<space>codegolf
– Mr. Xcoder – 2017-08-17T10:20:19.580Can I return an array of the output letters? – TheLethalCoder – 2017-08-17T10:32:21.963
Can we return the letters separated by a newline or as an array? – Mr. Xcoder – 2017-08-17T10:33:30.150
1@Mr.Xcoder yes you can – Skidsdev – 2017-08-17T10:43:34.303