Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > Sort > compareByValue

Sort.compareByValue() method

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;

Parameters

ParameterTypeDescription
xany
yany

Returns:

number

-1 if x is smaller than y, 1 if x is greater than y, or 0 if the values are equal.

Remarks

The JavaScript ordering is generalized so that undefined < null < all other values.

Example

let array: number[] = [3, 6, 2];
array.sort(Sort.compareByValue); // [2, 3, 6]