Skip to content

Instantly share code, notes, and snippets.

@gpbmike
Created August 15, 2008 22:00
Show Gist options
  • Save gpbmike/5663 to your computer and use it in GitHub Desktop.
Save gpbmike/5663 to your computer and use it in GitHub Desktop.
var arr = [1,3,2,4];
console.log(arr);
var sorted_arr = arr.sort();
console.log(sorted_arr);
console.log(arr);
// prints what i don't want
// [1,3,2,4]
// [1,2,3,4]
// [1,2,3,4]
var arr = [1,3,2,4];
console.log(arr);
var sorted_arr = arr.slice().sort();
console.log(sorted_arr);
console.log(arr);
// prints what i want!
// [1,3,2,4]
// [1,2,3,4]
// [1,3,2,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment