http://www.perlmonks.org?node_id=589295


in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

Because I really have come to hate for loops, here is one in Javascript which uses a fixed point combinator to do the looping and filtering of the list.

function (orig, i, acc) { if (i > orig.length) return acc; if (orig[i] != "") acc[acc.length] = orig[i]; return arguments.callee(orig, (i + 1), acc); }(" one two three four ".split(" ").reverse(), 0, []).join(" ")

-stvn