Created
July 27, 2016 19:51
-
-
Save sax1johno/6f6d9257ffc60a784ef03c00fd1bf40d to your computer and use it in GitHub Desktop.
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 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