mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 10:03:15 -05:00
14 lines
445 B
TypeScript
14 lines
445 B
TypeScript
'use strict';
|
|
|
|
export namespace Arrays {
|
|
export function uniqueBy<T>(array: T[], accessor: (item: T) => any, predicate?: (item: T) => boolean): T[] {
|
|
const uniqueValues = Object.create(null);
|
|
return array.filter(_ => {
|
|
const value = accessor(_);
|
|
if (uniqueValues[value]) return false;
|
|
|
|
uniqueValues[value] = accessor;
|
|
return predicate ? predicate(_) : true;
|
|
});
|
|
}
|
|
} |