import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'groupBy' } ) export class GroupByPipe implements PipeTransform { transform ( array , f ) { var groups = { } ; array . forEach ( ( o ) => { var group = JSON . stringify ( f ( o ) ) ; groups [ group ] = groups [ group ] || [ ] ; groups [ group ] . push ( o ) ; } ) ; return Object . keys ( groups ) . map ( ( group ) => { return groups [ group ] ; } ) ; } }