Home > @microsoft/node-core-library > Sort > isSortedBy

Sort.isSortedBy() method

Returns true if the array is already sorted by the specified key.

Signature:

static isSortedBy<T>(array: T[], keySelector: (element: T) => any, comparer?: (x: any, y: any) => number): boolean;

Parameters

Parameter Type Description
array T[]  
keySelector (element: T) => any  
comparer (x: any, y: any) => number  

Returns:

boolean

Example

let array: string[] = [ 'a', 'bb', 'ccc' ];
Sort.isSortedBy(array, x => x.length); // true