RoadmapShopEvents
Skip to main content

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

Sort class

Operations for sorting collections.

Signature:

export declare class Sort 

Remarks

NOTE: Prior to Node 11.x, the Array.sort() algorithm is not guaranteed to be stable. For maximum compatibility, consider using LegacyAdapters.sortStable() instead of Array.sort().

Methods

MethodModifiersDescription
compareByValue(x, y)staticCompares x and y using the JavaScript > and < operators. This function is suitable for usage as the callback for array.sort().
isSorted(array, comparer)staticReturns true if the array is already sorted.
isSortedBy(array, keySelector, comparer)staticReturns true if the array is already sorted by the specified key.
sortBy(array, keySelector, comparer)staticSorts the array according to a key which is obtained from the array elements. The result is guaranteed to be a stable sort.
sortMapKeys(map, keyComparer)staticSorts the entries in a Map object according to the map keys. The result is guaranteed to be a stable sort.
sortSet(set, comparer)staticSorts the entries in a Set object. The result is guaranteed to be a stable sort.
sortSetBy(set, keySelector, keyComparer)staticSorts the entries in a Set object according to the specified keys. The result is guaranteed to be a stable sort.