import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'sharedOrderBy' } ) export class OrderByPipe implements PipeTransform { param data param key param descending return { any [ ] } transform ( data , keys , descending = false ) { data . sort ( ( n1 , n2 ) => { for ( const key of keys ) { n1 = n1 [ key ] ; n2 = n2 [ key ] ; } if ( ! n1 ) { return 1 ; } else if ( ! n2 ) { return - 1 ; } if ( ! descending ) { if ( n1 > n2 ) { return 1 ; } else if ( n1 < n2 ) { return - 1 ; } } else { if ( n1 < n2 ) { return 1 ; } else if ( n1 > n2 ) { return - 1 ; } } return 0 ; } ) ; return data ; } }