Returns a comparator that puts null and undefined before 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.
Native Array.prototype.sort always moves undefined and empty slots to the end without calling
the comparator, so with native sort this moves only null to the front.
Time: O(1) plus at most one call of comparator per comparison.
Returns a comparator that puts
nullandundefinedbefore every other value, treats them as equal to each other, and orders the rest withcomparator(natural order when omitted).comparatoris never called withnullorundefined.Native
Array.prototype.sortalways movesundefinedand empty slots to the end without calling the comparator, so with nativesortthis moves onlynullto the front.Time: O(1) plus at most one call of
comparatorper comparison.