Created
December 2, 2018 23:06
-
-
Save chrdek/7cfcb7e16ca3fd69ba324bd2cc080a9e to your computer and use it in GitHub Desktop.
Simple loop usage for string reversal (without using reverse())
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
//String reverse function with for loop | |
String.prototype.reverseString = function(){ | |
s=[...this]; r=[]; | |
for(i=0;;){if(i!=s.length){r.push(s.pop())}else{break;}} | |
return r.join(''); | |
} | |
//Sample usage: "thisisreversed12".reverseString(); | |
//Output from usage | |
//"21desreversisiht" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment