Reverse words in a string: Difference between revisions

Content added Content deleted
No edit summary
(Add Jsish)
Line 1,624: Line 1,624:


----------------------- Robert Frost</lang>
----------------------- Robert Frost</lang>

=={{header|Jsish}}==
From Javascript entry.
<lang javascript>var strReversed =
"---------- Ice and Fire ------------\n
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
\n... elided paragraph last ...\n
Frost Robert -----------------------";
function reverseString(s) {
return s.split('\n').map(
function (line) {
return line.split().reverse().join(' ');
}
).join('\n');
}

;reverseString('Hey you, Bub!');
;strReversed;
;reverseString(strReversed);

/*
=!EXPECTSTART!=
reverseString('Hey you, Bub!') ==> Bub! you, Hey
strReversed ==> ---------- Ice and Fire ------------

fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I

... elided paragraph last ...

Frost Robert -----------------------
reverseString(strReversed) ==> ------------ Fire and Ice ----------

Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.

... last paragraph elided ...

----------------------- Robert Frost
=!EXPECTEND!=
*/</lang>

{{out}}
<pre>
prompt$ jsish -u reverseWords.jsi
[PASS] reverseWords.jsi</pre>


=={{header|Julia}}==
=={{header|Julia}}==