import { Injectable } from '@angular/core' ; /**
 * Sorting service
 */ @ Injectable ( { providedIn : 'root' , } ) export class SortingService { /**
     * Sort the list by date field
     */ sortListByDate < T > ( list , field ) { list . sort ( ( obj1 , obj2 ) => { const date1 = new Date ( obj1 [ field ] ) ; const date2 = new Date ( obj2 [ field ] ) ; return date1 > date2 ? - 1 : date1 < date2 ? 1 : 0 ; } ) ; } /**
     * Sort the list by any key
     */ sortListByNumber < T > ( list , field ) { list . sort ( ( obj1 , obj2 ) => { return obj2 [ field ] - obj1 [ field ] ; } ) ; } }