main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
293 bytes
|
Line | |
---|
1 | // @flow
|
---|
2 |
|
---|
3 | export default function uniqueBy<T>(arr: Array<T>, fn: T => any): Array<T> {
|
---|
4 | const identifiers = new Set();
|
---|
5 |
|
---|
6 | return arr.filter(item => {
|
---|
7 | const identifier = fn(item);
|
---|
8 |
|
---|
9 | if (!identifiers.has(identifier)) {
|
---|
10 | identifiers.add(identifier);
|
---|
11 | return true;
|
---|
12 | }
|
---|
13 | });
|
---|
14 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.