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:
All what the sort function needs is a function that returns either positive, zero, or a negative number.