Created
September 8, 2017 19:55
-
-
Save juanigallo/4c3d39c1a87bfb1f4bddc9a3601e84d5 to your computer and use it in GitHub Desktop.
Reverse a string with JavaScript
This file contains hidden or 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
//Using built-in functions | |
function reverseString(str) { | |
return str.split("").reverse().join(""); | |
} | |
//Without built-in functions | |
function reverseString(str) { | |
var newString = ""; | |
for (var i = str.length - 1; i >= 0; i--) { | |
newString += str[i]; | |
} | |
return newString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment