Function alphabeticalNullable

  • For use with sorting functions such as sortWith or the built-in Array.prototype.sort(). Sorts in ascending alphabetical order, ignoring all spaces and punctuation. For the same letter, upper case letters come before lower case letters. null follows all strings, with undefined at the very end.

    For languages other than English, or for other conventions regarding punctuation, letter case, etc., use alphaLocaleNullable.

    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().

    As of this writing (January 3, 2023), some Android browsers do not support this function..

    Example

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

    const sortAlpha = A.sortWith(C.alphabeticalNullable);
    sortSv(["a", "a c", null, "ab", "Ab"]); // ["a", "Ab", "ab", "a c", null]

    Parameters

    • a: undefined | null | string
    • b: undefined | null | string

    Returns number