My difficulty here could be my mathematical illiteracy, but I was trying to sort some numbers in a JavaScript array and this is the solution I found online. It does indeed w
If Function(a, b) is less than 0, sort a to an index lower than b, i.e. a comes first.
If Function(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different elements.
Note: the ECMAscript standard does not guarantee this behaviour, and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.
If Function(a, b) is greater than 0, sort b to an index lower than a, i.e. b comes first.
Function(a, b) must always return the same value when given a specific pair of elements a and b as its two arguments. If inconsistent results are returned then the sort order is undefined.