interface SortType { [ key ] : any ; } export const sortByDateKey = ( key , ordering = 'asc' ) => ( a , b ) : number => { const dateA = new Date ( a [ key ] ) ; const dateB = new Date ( b [ key ] ) ; const diff = dateA . getTime ( ) - dateB . getTime ( ) ; if ( diff < 0 ) return ordering === 'asc' ? - 1 : 1 ; if ( diff > 0 ) return ordering === 'asc' ? 1 : - 1 ; return 0 ; } ; export const sortByNumberKey = ( key , ordering = 'asc' ) => ( a , b ) : number => { const diff = a [ key ] - b [ key ] ; if ( diff < 0 ) return ordering === 'asc' ? - 1 : 1 ; if ( diff > 0 ) return ordering === 'asc' ? 1 : - 1 ; return 0 ; } ;