combineSortFns
Chains multiple sort functions into a single comparator: the first function
decides the order unless it reports a tie (0), in which case the next
function is tried, and so on.
Lets you compose comparators of different kinds — e.g. a boolean-property
comparator from createSortByBooleanFn followed by a string-property
comparator from createSortByStringFn — which a single multi-key call
cannot express, since that coerces every key to the same comparison type.
Available since v3.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fns | readonly SortFn<T>[] | Sort functions to try, in priority order. An empty list produces a stable no-op comparator (all elements compare equal). |
Returns
Section titled “Returns”SortFn<T> — A single sort function equivalent to applying fns in order
Examples
Section titled “Examples”Default items first, then alphabetical
Section titled “Default items first, then alphabetical”Chain a boolean comparator with a string comparator to break ties.
Falls through when the first comparator ties
Section titled “Falls through when the first comparator ties”A 0 result from the first function moves on to the next one.
Related Types
Section titled “Related Types”SortFn
Section titled “SortFn”Sort function type for arrays
