Creates a comparator that compares iterables (e.g. arrays) in lexicographic
order.
You must provide a comparator (such as naturalOrder) for comparing
corresponding pairs of elements. You can provide multiple comparator
arguments, which are combined similarly to compareWith.
The returned comparator expects two iterables. It compares their
corresponding elements pairwise until a non-equal pair is found. If either
iterable ends before a non-equal pair is found, that shorter iterable is
considered less than the other. If all elements are equal, the iterables are
considered equal.
constpeople = [ { firstName:"Fred", lastName:"Johnson" }, { firstName:"Calvin", lastName:"Hobbes" }, ]; // sort list of people by full name people.sort( compareBy( (person) => [person.firstName, person.lastName], compareEachWith(String.prototype.localeCompare), ); );
Creates a comparator that compares iterables (e.g. arrays) in lexicographic order.
You must provide a comparator (such as naturalOrder) for comparing corresponding pairs of elements. You can provide multiple comparator arguments, which are combined similarly to compareWith.
The returned comparator expects two iterables. It compares their corresponding elements pairwise until a non-equal pair is found. If either iterable ends before a non-equal pair is found, that shorter iterable is considered less than the other. If all elements are equal, the iterables are considered equal.