Travis build: 1368
This commit is contained in:
52
README.md
52
README.md
@ -142,6 +142,8 @@ average(1, 2, 3);
|
||||
* [`take`](#take)
|
||||
* [`takeRight`](#takeright)
|
||||
* [`union`](#union)
|
||||
* [`unionBy`](#unionby)
|
||||
* [`unionWith`](#unionwith)
|
||||
* [`uniqueElements`](#uniqueelements)
|
||||
* [`without`](#without)
|
||||
* [`zip`](#zip)
|
||||
@ -1892,6 +1894,56 @@ union([1, 2, 3], [4, 3, 2]); // [1,2,3,4]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### unionBy
|
||||
|
||||
Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.
|
||||
|
||||
Create a `Set` by applying all `fn` to all values of `a`.
|
||||
Create a `Set` from `a` and all elements in `b` whose value, after applying `fn` does not match a value in the previously created set.
|
||||
Return the last set converted to an array.
|
||||
|
||||
```js
|
||||
const unionBy = (a, b, fn) => {
|
||||
const s = new Set(a.map(v => fn(v)));
|
||||
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### unionWith
|
||||
|
||||
Returns every element that exists in any of the two arrays once, using a provided comparator function.
|
||||
|
||||
Create a `Set` with all values of `a` and values in `b` for which the comparator finds no matches in `a`, using `Array.findIndex()`.
|
||||
|
||||
```js
|
||||
const unionWith = (a, b, comp) =>
|
||||
Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)]));
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### uniqueElements
|
||||
|
||||
Returns all unique values of an array.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -6,9 +6,7 @@ Create a `Set` with all values of `a` and values in `b` for which the comparator
|
||||
|
||||
```js
|
||||
const unionWith = (a, b, comp) =>
|
||||
Array.from(
|
||||
new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)])
|
||||
);
|
||||
Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)]));
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user