Created
May 1, 2015 15:52
-
-
Save stepheneyer/43e8c1fdaaaa923c4976 to your computer and use it in GitHub Desktop.
reverse a string using a for loop
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
function reverse(string) { | |
var rev = ''; | |
for (var i = string.length - 1; i >= 0; i--) | |
rev += string[i]; | |
return rev; | |
} | |
reverse("Hello"); | |
//=> returns "olleH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment