javascript-collections-framework
    Preparing search index...

    Function nullsLast

    • Returns a comparator that puts null and undefined after every other value, treats them as equal to each other, and orders the rest with comparator (natural order when omitted). comparator is never called with null or undefined.

      Time: O(1) plus at most one call of comparator per comparison.

      Type Parameters

      • T

      Parameters

      • Optionalcomparator: Comparator<T>

        Orders the values that are not null or undefined.

      Returns Comparator<T | null | undefined>

      The comparator.

      TypeError when comparator is given but is not a function (including null).

      NullElementError, ClassCastError or TypeError (from the comparator, when natural order is used) as described for naturalOrder.

      [null, 3, 1].sort(nullsLast()) // [1, 3, null]