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.
o as it is not the next letter of the alphabet.
d as it is the next letter of the alphabet, and keep
e as it is the next letter too.
l, and keep
Your final snippet would then be
- Capitalisation should be maintained, so
CodEgolFwould result in
- 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.
zZis the last letter of the alphabet. There are no letters after it, the alphabet does not loop.
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
This is code-golf, so fewest bytes in each language wins!