Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created July 27, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sax1johno/6f6d9257ffc60a784ef03c00fd1bf40d to your computer and use it in GitHub Desktop.
Save sax1johno/6f6d9257ffc60a784ef03c00fd1bf40d to your computer and use it in GitHub Desktop.
var reverseString = function(stringToReverse) {
var finalString = []; // I prefer to use arrays instead of strings.
// loop through the string, starting at the end.
for (var i = stringToReverse.length; i > 0; i--) {
// push the character at the current index into the finalString array
finalString.push(stringToReverse[i]);
}
// Join the characters in the array into a string and return the string.
return finalString.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment