Created
August 5, 2011 15:35
-
-
Save DavidQL/1127789 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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, 4, 5, 13, 22] | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment