import { LegacyAdapters } from './LegacyAdapters' ; 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()`.
 *
 *  public export class Sort { remarks returns example public static compareByValue ( x , y ) { if ( x === y ) { return 0 ; } if ( x === undefined ) { return - 1 ; } if ( y === undefined ) { return 1 ; } if ( x === null ) { return - 1 ; } if ( y === null ) { return 1 ; } if ( x < y ) { return - 1 ; } if ( x > y ) { return 1 ; } return 0 ; } example public static sortBy < T > ( array , keySelector , comparer = Sort . compareByValue ) { LegacyAdapters . sortStable ( array , ( x , y ) => comparer ( keySelector ( x ) , keySelector ( y ) ) ) ; } /**
     * Returns true if the array is already sorted.
     */ public static isSorted < T > ( array , comparer = Sort . compareByValue ) { let previous = undefined ; for ( const element of array ) { if ( comparer ( previous , element ) > 0 ) { return false ; } previous = element ; } return true ; } example public static isSortedBy < T > ( array , keySelector , comparer = Sort . compareByValue ) { let previousKey = undefined ; for ( const element of array ) { const key = keySelector ( element ) ; if ( comparer ( previousKey , key ) > 0 ) { return false ; } previousKey = key ; } return true ; } example public static sortMapKeys < K , V > ( map , keyComparer = Sort . compareByValue ) { const pairs = Array . from ( map . entries ( ) ) ; if ( Sort . isSortedBy ( pairs , ( x ) => x [ 0 ] , keyComparer ) ) { return ; } Sort . sortBy ( pairs , ( x ) => x [ 0 ] , keyComparer ) ; map . clear ( ) ; for ( const pair of pairs ) { map . set ( pair [ 0 ] , pair [ 1 ] ) ; } } example public static sortSetBy < T > ( set , keySelector , keyComparer = Sort . compareByValue ) { const array = Array . from ( set ) ; if ( Sort . isSortedBy ( array , keySelector , keyComparer ) ) { return ; } LegacyAdapters . sortStable ( array , ( x , y ) => keyComparer ( keySelector ( x ) , keySelector ( y ) ) ) ; set . clear ( ) ; for ( const item of array ) { set . add ( item ) ; } } example public static sortSet < T > ( set , comparer = Sort . compareByValue ) { const array = Array . from ( set ) ; if ( Sort . isSorted ( array , comparer ) ) { return ; } LegacyAdapters . sortStable ( array , ( x , y ) => comparer ( x , y ) ) ; set . clear ( ) ; for ( const item of array ) { set . add ( item ) ; } } }