Reverse words in a string: Difference between revisions
→Expanded existing code to show escaping of multi-line strings in JavaScript. Added output
No edit summary |
|||
Line 937:
=={{header|JavaScript}}==
<lang javascript>var strReversed =
"---------- Ice and Fire ------------\n\
\n\
fire, in end will world the say Some\n\
ice. in say Some\n\
desire of tasted I've what From\n\
fire. favor who those with hold I\n\
\n\
... elided paragraph last ...\n\
\n\
Frost Robert -----------------------";
function reverseString(s) {
return s.split('\n').map(
}
).join('\n');
}
</lang>▼
console.log(
reverseString(strReversed)
▲);</lang>
Output:
<pre>------------ 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</pre>
=={{header|jq}}==
|