argos/dmp-frontend/src/app/utilities/enhancers/groupBy.ts

12 lines
278 B
TypeScript

interface Array<T> {
groupBy<E, J>(by: (item: T) => J): Array<Array<E>>;
}
Array.prototype.groupBy = function (f: Function) {
return this.reduce((ys: any, x: any) => {
ys[f.call(this, x)] = ys[f.call(this, x)] || [];
ys[f.call(this, x)].push(x);
return ys;
}, []);
};