stack

Home > @infiniteobjects/core-library-web > Sort > sortBy

Sort.sortBy() method

Warning: This API is now obsolete.

Use Arrays.sortBy() instead.

Sorts the array according to a key which is obtained from the array elements. The result is guaranteed to be a stable sort.

Signature:

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

Parameters

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

Returns:

void

Remarks

This method changes the array in place

Example

let array: string[] = [ 'aaa', 'bb', 'c' ];
Sort.sortBy(array, x => x.length);  // [ 'c', 'bb', 'aaa' ]