Skip to content

Instantly share code, notes, and snippets.

@DavidQL
Created July 27, 2011 03:24
Show Gist options
  • Save DavidQL/1108606 to your computer and use it in GitHub Desktop.
Save DavidQL/1108606 to your computer and use it in GitHub Desktop.
(function() {
var sorted_array = [1,22,13,4,5].sort(function(a, b) {
// you get a and b to sort.
// if the function returns a..
// negative number: a comes ahead in sort order
// a positive number: b comes first
return a-b;
});
console.log(sorted_array);
// returns [1, 13, 22, 4, 5]
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment