Created
August 23, 2018 18:32
-
-
Save imgsrc/9e30713170f6c99991c56bf7319f7dbb to your computer and use it in GitHub Desktop.
Reverse word
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
var string = "Welcome to this Javascript Guide!"; | |
// Output becomes !ediuG tpircsavaJ siht ot emocleW | |
var reverseEntireSentence = reverseBySeparator(string, ""); | |
// Output becomes emocleW ot siht tpircsavaJ !ediuG | |
var reverseEachWord = reverseBySeparator(reverseEntireSentence, " "); | |
function reverseBySeparator(string, separator) { | |
return string.split(separator).reverse().join(separator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment