Skip to content

Instantly share code, notes, and snippets.

@naush
Created July 14, 2010 15:26
Show Gist options
  • Save naush/475556 to your computer and use it in GitHub Desktop.
Save naush/475556 to your computer and use it in GitHub Desktop.
String.prototype.reverse = makeReverseFunction();
function makeReverseFunction() {
function reverse() {
var string_array = this.split("");
var length = this.length;
var swap = function(a, b) {
temp = string_array[a];
string_array[a] = string_array[b];
string_array[b] = temp;
}
for (head = 0; head < length/2; head++) {
swap(head, length-head);
}
return string_array.join("");
}
return reverse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment