Update differenceBy
This commit is contained in:
@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user