Created
January 23, 2015 00:55
-
-
Save bradoyler/8e94d2e5e31dcffb5227 to your computer and use it in GitHub Desktop.
reverse string, like a paragraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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