Function numericNullableDesc

  • For use with sorting functions such as sortWith or the built-in Array.prototype.sort(). Sorts in descending numerical order, with valid numbers followed by NaN, then null, then undefined.

    Remarks

    JavaScript's Array.prototype.sort() places undefined at the end without even calling the comparator. This comparator, however, still handles undefined so that it can be used with sort implementations not based on Array.prototype.sort().

    Example

    import * as A from "flurp/array";
    import * as C from "flurp/comparator";

    const sortNumbers = A.sortWith(C.numericNullableDesc);
    sortNumbers([30, NaN, 6, 1, undefined, 200, null, 5]); // [200, 30, 6, 5, 1, NaN, null, undefined]

    Parameters

    • x: undefined | null | number
    • y: undefined | null | number

    Returns 0 | 1 | -1