.sort()
with custom function must return number indicating witch item must be placed in front:
< 0 - First element must be placed before second
0 - Both elements is equal, do not change order.
> 0 - Second element must be placed before first.
Usually b - a
means descendant sorting while a - b
means ascendant ordering.
What algorithm is used to sort elements depends on browser implementation of .sort
. Check comparison of them: