RosettaCodeData/Task/Odd-word-problem/CoffeeScript/odd-word-problem-2.coffee

24 lines
425 B
CoffeeScript

isWordChar = (c) -> /^\w/.test c
isLastChar = (c) -> c is '.'
oddWord = (get, put) ->
forwardWord = ->
loop
c = get()
put(c)
unless isWordChar(c)
return not isLastChar(c)
reverseWord = (outputPending = (->)) ->
c = get()
if isWordChar(c)
reverseWord ->
put(c)
outputPending()
else
outputPending()
put(c)
return not isLastChar(c)
continue while forwardWord() and reverseWord()