Home > @rushstack/node-core-library > Sort > isSortedBy
Sort.isSortedBy() method
Returns true if the collection is already sorted by the specified key.
Signature:
static isSortedBy<T>(collection: Iterable<T>, keySelector: (element: T) => any, comparer?: (x: any, y: any) => number): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
collection | Iterable<T> | |
keySelector | (element: T) => any | |
comparer | (x: any, y: any) => number | (Optional) |
Returns:
boolean
Example
let array: string[] = [ 'a', 'bb', 'ccc' ];
Sort.isSortedBy(array, x => x.length); // true