
Ahmed Elgendy thinks this is interesting:
Next we need to write our own function that knows how to compare two values in the array. Now, this is an array of numbers, so our function will need to compare two numbers at a time. Assume we’re going to sort the numbers in ascending order; for that the sort
method expects us to return something greater than 0 if the first number is greater than the second, 0 if they are equal, and something less than 0 if the first number is less than the second. Like this:
From
 10. First Class Functions: Liberated functions
 from Head First JavaScript Programming
 Publisher: O'Reilly Media, Inc.
 Released: March 2014
Note
All what the sort function needs is a function that returns either positive, zero, or a negative number.
Minimise