Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)

by jdporter (Canon)
on Dec 12, 2006 at 16:03 UTC ( #589307=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

Interesting... It works fine in EcmaScript. Or at least Jscript. :-)
So how about

" one two three four ".split(/ +/).reverse().join(" ")
We're building the house of the future together.


Comment on Re^4: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
Download Code
Replies are listed 'Best First'.
Re^5: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by stvn (Monsignor) on Dec 12, 2006 at 16:09 UTC

    Yup, that one works. Boring, but it works ;)

    -stvn
Re^5: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by AltBlue (Chaplain) on Dec 14, 2006 at 15:04 UTC
    Trimming the string is still necessary in order to comply with the specs. Yes, very boring ;-)
    function reverseWords(str) { return str.replace(/^\s+/,'').replace(/\s+$/,'').split(/\s+/).revers +e().join(' '); };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://589307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2015-08-01 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls