Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created January 23, 2015 00:55
Show Gist options
  • Save bradoyler/8e94d2e5e31dcffb5227 to your computer and use it in GitHub Desktop.
Save bradoyler/8e94d2e5e31dcffb5227 to your computer and use it in GitHub Desktop.
reverse string, like a paragraph
/* input
---------- 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 -----------------------
*/
function reverseString(s) {
return s.split('\n').map(function(line) {
return line.split(/\s/).reverse().join(' ');
}).join('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment