Skip to content

Instantly share code, notes, and snippets.

@hiroshi-maybe
Created May 1, 2013 09:10
Show Gist options
  • Select an option

  • Save hiroshi-maybe/5494419 to your computer and use it in GitHub Desktop.

Select an option

Save hiroshi-maybe/5494419 to your computer and use it in GitHub Desktop.
A function to reverse a list (loop: n/2, space: n).
var reverse = function (a) {
for (var i=0, arrayLen=a.length ; i<arrayLen/2; i+=1) {
var temp = a[arrayLen-i-1];
a[arrayLen-i-1] = a[i];
a[i] = temp;
}
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment