Reverse words in a string: Difference between revisions

Line 2,513:
<lang R>
whack <- function(s) {
paste( rev( unlist(strsplit(s, " ")[[1]])), collapse=' ' ) }
 
poem <- unlist( strsplit(
'------------ Eldorado ----------
 
Line 2,527:
Eldorado!" for seek you "If
 
Poe Edgar -----------------------', "\n")[[1]])
 
for (line in poem) cat( whack(line), "\n" )
Line 2,552:
 
<lang R>
> `{` <- function(s) rev(unlist(strsplit(s, " ")[[1]]))
> {"one two three four five"}
[1] "five" "four" "three" "two" "one"
Anonymous user