Skip to content

Instantly share code, notes, and snippets.

@NdYAG
Created October 16, 2012 12:30
Show Gist options
  • Save NdYAG/3898976 to your computer and use it in GitHub Desktop.
Save NdYAG/3898976 to your computer and use it in GitHub Desktop.
Reverse a string in Javascript
String.prototype.reverse=function(){
var that=this;//or this points to window
function rev(len,result){
if(len==0)
return result;
else{
//console.log(this);
return rev(len-1,result+that[len-1]);
}
}
return rev(this.length,"");
}
'string'.reverse();//'gnirts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment