We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ccc29e3 commit ea6fdbaCopy full SHA for ea6fdba
src/system/array.ts
@@ -1,6 +1,15 @@
1
'use strict';
2
3
export namespace Arrays {
4
+ export function groupBy<T>(array: T[], accessor: (item: T) => any): T[] {
5
+ return array.reduce((previous, current) => {
6
+ const value = accessor(current);
7
+ previous[value] = previous[value] || [];
8
+ previous[value].push(current);
9
+ return previous;
10
+ }, Object.create(null));
11
+ }
12
+
13
export function uniqueBy<T>(array: T[], accessor: (item: T) => any, predicate?: (item: T) => boolean): T[] {
14
const uniqueValues = Object.create(null);
15
return array.filter(_ => {
0 commit comments