Home > @infiniteobjects/core-library-web > Sort > compareByValue
Compares x
and y
using the JavaScript >
and <
operators. This function is suitable for usage as the callback for array.sort()
.
Signature:
static compareByValue(x: any, y: any): number;
Parameter | Type | Description |
---|---|---|
x | any | |
y | any |
Returns:
number
-1 if x
is smaller than y
, 1 if x
is greater than y
, or 0 if the values are equal.
The JavaScript ordering is generalized so that undefined
< null
< all other values.
let array: number[] = [3, 6, 2];
array.sort(Sort.compareByValue); // [2, 3, 6]