Skip to content

Instantly share code, notes, and snippets.

@juanigallo
Created September 8, 2017 19:55
Show Gist options
  • Save juanigallo/4c3d39c1a87bfb1f4bddc9a3601e84d5 to your computer and use it in GitHub Desktop.
Save juanigallo/4c3d39c1a87bfb1f4bddc9a3601e84d5 to your computer and use it in GitHub Desktop.
Reverse a string with JavaScript
//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