/**
 * Returns -1, 0 or 1 by comparing two values, appropriate as a comparison function for Array.sort()
 */ export function compareForSort < T > ( value1 , value2 , descending ? ) { if ( descending ) { [ value1 , value2 ] = [ value2 , value1 ] ; } if ( value1 < value2 ) { return - 1 ; } else if ( value1 > value2 ) { return 1 ; } else { return 0 ; } } param input param property export function sortArray < T , V > ( input , getSortValue , options ? ) { return input . sort ( ( a , b ) => { const value1 = getSortValue ( a ) ; const value2 = getSortValue ( b ) ; return compareForSort ( value1 , value2 , options ?. descending ) ; } ) ; } param input param property export function sortArrayByProperty < T , K extends keyof T > ( input , property , options ? ) { return sortArray ( input , element => element [ property ] , options ) ; }