RankCompare: ((left, right) => RankComparison)

Returns -1, 0, or 1 depending on whether the rank of left is respectively before, tied-with, or after the rank of right.

This comparison function is valid as argument to Array.prototype.sort. This is sometimes described as a "total order" but, depending on your definitions, this is technically incorrect because it may return 0 to indicate that two distinguishable elements such as -0 and 0 are tied (i.e., are in the same equivalence class for the purposes of this ordering). If each such equivalence class is a rank and ranks are disjoint, then this "rank order" is a true total order over these ranks. In mathematics this goes by several other names such as "total preorder".

This function establishes a total rank order over all passables. To do so it makes arbitrary choices, such as that all strings are after all numbers. Thus, this order is not intended to be used directly as a comparison with useful semantics. However, it must be closely enough related to such comparisons to aid in implementing lookups based on those comparisons. For example, in order to get a total order among ranks, we put NaN after all other JavaScript "number" values (i.e., IEEE 754 floating-point values). But otherwise, we rank JavaScript numbers by signed magnitude, with 0 and -0 tied. A semantically useful ordering would also compare magnitudes, and so agree with the rank ordering of all values other than NaN. An array sorted by rank would enable range queries by magnitude.

Type declaration

Generated using TypeDoc