Created
March 29, 2012 12:29
-
-
Save be5invis/2236963 to your computer and use it in GitHub Desktop.
Answer for Ninputer: merge spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rest(s) = s.slice 1 | |
def mergeSpaces(s) = phase_normal s | |
where phase_normal(s) = piecewise | |
when(not s) s | |
when(s[0] == ' ') s[0] + phase_space rest s | |
otherwise s[0] + phase_normal rest s | |
phase_space(s) = piecewise | |
when(not s) s | |
when(s[0] == ' ') phase_space rest s | |
otherwise s[0] + phase_normal rest s | |
trace mergeSpaces 'abc def' | |
trace mergeSpaces 'abc def' | |
trace mergeSpaces 'a bcd ef' | |
trace ('[' + mergeSpaces ' ' + ']') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment