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(" ")
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by jdporter (Paladin) on Dec 12, 2006 at 15:50 UTC | |
by stvn (Monsignor) on Dec 12, 2006 at 15:56 UTC | |
by jdporter (Paladin) on Dec 12, 2006 at 16:03 UTC | |
by stvn (Monsignor) on Dec 12, 2006 at 16:09 UTC | |
by AltBlue (Chaplain) on Dec 14, 2006 at 15:04 UTC |