Home > @rushstack/node-core-library > LegacyAdapters > sortStable

LegacyAdapters.sortStable() method

Prior to Node 11.x, the Array.sort() algorithm is not guaranteed to be stable. If you need a stable sort, you can use sortStable() as a workaround.

Signature:

static sortStable<T>(array: T[], compare?: (a: T, b: T) => number): void;

Parameters

Parameter Type Description
array T[]  
compare (a: T, b: T) => number  

Returns:

void

Remarks

On NodeJS 11.x and later, this method simply calls the native Array.sort(). For earlier versions, it uses an implementation of Timsort, which is the same algorithm used by modern NodeJS.