Skip to content

Instantly share code, notes, and snippets.

@JoeChapman
Created March 21, 2012 13:59
Show Gist options
  • Select an option

  • Save JoeChapman/2147092 to your computer and use it in GitHub Desktop.

Select an option

Save JoeChapman/2147092 to your computer and use it in GitHub Desktop.
Sorting numeric values in ascending order with a compare function
var arr = [300, 40, 5];
arr.sort(function (a, b) {
return a - b;
});
// Result
5, 40, 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment