Simplify unionBy
This commit is contained in:
@ -8,7 +8,7 @@ Return the last set converted to an array.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const unionBy = (a, b, fn) => {
|
const unionBy = (a, b, fn) => {
|
||||||
const s = new Set(a.map(v => fn(v)));
|
const s = new Set(a.map(fn));
|
||||||
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
|
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const unionBy = (a, b, fn) => {
|
const unionBy = (a, b, fn) => {
|
||||||
const s = new Set(a.map(v => fn(v)));
|
const s = new Set(a.map(fn));
|
||||||
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
|
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
|
||||||
};
|
};
|
||||||
module.exports = unionBy;
|
module.exports = unionBy;
|
||||||
|
|||||||
Reference in New Issue
Block a user