Skip to content

ts-ds / defaultCompare

Function: defaultCompare() ​

ts
function defaultCompare<T>(a, b): number;

Defined in: sort/utils.ts:25

Default ascending order for numbers, strings and other values comparable with <.

  • Strings are compared by UTF-16 code units: 'B' < 'a'. Use (a, b) => a.localeCompare(b) for alphabetical order.
  • NaN has no place in the numeric order, so it is treated as greater than any other value and ends up at the end of the array.

Type Parameters ​

Type ParameterDescription
T

Parameters ​

ParameterTypeDescription
aTFirst value to compare.
bTSecond value to compare.

Returns ​

number

-1, 0 or 1.

MIT License