Update differenceBy

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-19 18:52:00 +03:00
parent 600ee35644
commit 52f9c16e73

View File

@ -5,7 +5,9 @@ tags: array,intermediate
Returns the difference between two arrays, after applying the provided function to each array element of both. Returns the difference between two arrays, after applying the provided function to each array element of both.
- Create a `Set` by applying `fn` to each element in `b`, then use `Array.prototype.map()` to apply `fn` to each element in `a`, then `Array.prototype.filter()` - Create a `Set` by applying `fn` to each element in `b`.
- Use `Array.prototype.map()` to apply `fn` to each element in `a`.
- Use `Array.prototype.filter()` in combination with `fn` on `a` to only keep values not contained in `b`, using `Set.prototype.has()`.
```js ```js
const differenceBy = (a, b, fn) => { const differenceBy = (a, b, fn) => {