Function nullsFirst

  • Comparator that orders null or undefined values before anything else.

    All non-null values will be considered equal. So consider using compareWith to chain another comparator for comparing non-null values.

    Note that Array.sort always sorts undefined values to the end.

    Parameters

    • a: unknown
    • b: unknown

    Returns number

    nullsFirst(0, null) // -> 1
    nullsFirst(null, "foo") // -> -1
    nullsFirst(null, null) // -> 0
    nullsFirst(null, undefined) // -> 0