mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 01:25:43 -05:00
Adds groupBy function
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
export namespace Arrays {
|
||||
export function groupBy<T>(array: T[], accessor: (item: T) => any): T[] {
|
||||
return array.reduce((previous, current) => {
|
||||
const value = accessor(current);
|
||||
previous[value] = previous[value] || [];
|
||||
previous[value].push(current);
|
||||
return previous;
|
||||
}, Object.create(null));
|
||||
}
|
||||
|
||||
export function uniqueBy<T>(array: T[], accessor: (item: T) => any, predicate?: (item: T) => boolean): T[] {
|
||||
const uniqueValues = Object.create(null);
|
||||
return array.filter(_ => {
|
||||
|
||||
Reference in New Issue
Block a user