Skip to content

Instantly share code, notes, and snippets.

@chrdek
Created December 2, 2018 23:06
Show Gist options
  • Save chrdek/7cfcb7e16ca3fd69ba324bd2cc080a9e to your computer and use it in GitHub Desktop.
Save chrdek/7cfcb7e16ca3fd69ba324bd2cc080a9e to your computer and use it in GitHub Desktop.
Simple loop usage for string reversal (without using reverse())
//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