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

Sort.sortSetBy() method

Sorts the entries in a Set object according to the keys.

Signature:

static sortSetBy<T>(set: Set<T>, keySelector: (element: T) => any, keyComparer?: (x: T, y: T) => number): void;

Parameters

Parameter Type Description
set Set<T>  
keySelector (element: T) => any  
keyComparer (x: T, y: T) => number  

Returns:

void

Example

let set: Set<string> = new Set<string>();
set.add('aaa');
set.add('bb');
set.add('c');
Sort.sortSetBy(set, x => x.length);
console.log(Array.from(set)); // ['c', 'bb', 'aaa']