Travis build: 110
This commit is contained in:
108
README.md
108
README.md
@ -125,6 +125,7 @@ average(1, 2, 3);
|
|||||||
* [`dropWhile`](#dropwhile)
|
* [`dropWhile`](#dropwhile)
|
||||||
* [`everyNth`](#everynth)
|
* [`everyNth`](#everynth)
|
||||||
* [`filterNonUnique`](#filternonunique)
|
* [`filterNonUnique`](#filternonunique)
|
||||||
|
* [`filterNonUniqueBy`](#filternonuniqueby)
|
||||||
* [`findLast`](#findlast)
|
* [`findLast`](#findlast)
|
||||||
* [`findLastIndex`](#findlastindex)
|
* [`findLastIndex`](#findlastindex)
|
||||||
* [`flatten`](#flatten)
|
* [`flatten`](#flatten)
|
||||||
@ -185,6 +186,8 @@ average(1, 2, 3);
|
|||||||
* [`unionBy`](#unionby)
|
* [`unionBy`](#unionby)
|
||||||
* [`unionWith`](#unionwith)
|
* [`unionWith`](#unionwith)
|
||||||
* [`uniqueElements`](#uniqueelements)
|
* [`uniqueElements`](#uniqueelements)
|
||||||
|
* [`uniqueElementsBy`](#uniqueelementsby)
|
||||||
|
* [`uniqueElementsByRight`](#uniqueelementsbyright)
|
||||||
* [`unzip`](#unzip)
|
* [`unzip`](#unzip)
|
||||||
* [`unzipWith`](#unzipwith-)
|
* [`unzipWith`](#unzipwith-)
|
||||||
* [`without`](#without)
|
* [`without`](#without)
|
||||||
@ -1268,6 +1271,39 @@ filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1,3,5]
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### filterNonUniqueBy
|
||||||
|
|
||||||
|
Filters out the non-unique values in an array, based on a provided comparator function.
|
||||||
|
|
||||||
|
Use `Array.filter()` and `Array.every()` for an array containing only the unique values, based on the comparator function, `fn`.
|
||||||
|
The comparator function takes four arguments: the values of the two elements being compared and their indexes.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const filterNonUniqueBy = (arr, fn) =>
|
||||||
|
arr.filter((v, i) => arr.every((x, j) => (i == j) == fn(v, x, i, j)));
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
filterNonUniqueBy(
|
||||||
|
[
|
||||||
|
{ id: 0, value: 'a' },
|
||||||
|
{ id: 1, value: 'b' },
|
||||||
|
{ id: 2, value: 'c' },
|
||||||
|
{ id: 1, value: 'd' },
|
||||||
|
{ id: 0, value: 'e' }
|
||||||
|
],
|
||||||
|
(a, b) => a.id == b.id
|
||||||
|
); // [ { id: 2, value: 'c' } ]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### findLast
|
### findLast
|
||||||
|
|
||||||
Returns the last element for which the provided function returns a truthy value.
|
Returns the last element for which the provided function returns a truthy value.
|
||||||
@ -2900,6 +2936,78 @@ uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### uniqueElementsBy
|
||||||
|
|
||||||
|
Returns all unique values of an array, based on a provided comparator function.
|
||||||
|
|
||||||
|
Use `Array.reduce()` and `Array.some()` for an array containing only the first unique occurence of each value, based on the comparator function, `fn`.
|
||||||
|
The comparator function takes two arguments: the values of the two elements being compared.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const uniqueElementsBy = (arr, fn) =>
|
||||||
|
arr.reduce((acc, v) => {
|
||||||
|
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
uniqueElementsBy(
|
||||||
|
[
|
||||||
|
{ id: 0, value: 'a' },
|
||||||
|
{ id: 1, value: 'b' },
|
||||||
|
{ id: 2, value: 'c' },
|
||||||
|
{ id: 1, value: 'd' },
|
||||||
|
{ id: 0, value: 'e' }
|
||||||
|
],
|
||||||
|
(a, b) => a.id == b.id
|
||||||
|
); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### uniqueElementsByRight
|
||||||
|
|
||||||
|
Returns all unique values of an array, based on a provided comparator function.
|
||||||
|
|
||||||
|
Use `Array.reduce()` and `Array.some()` for an array containing only the last unique occurence of each value, based on the comparator function, `fn`.
|
||||||
|
The comparator function takes two arguments: the values of the two elements being compared.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const uniqueElementsByRight = (arr, fn) =>
|
||||||
|
arr.reduceRight((acc, v) => {
|
||||||
|
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
uniqueElementsByRight(
|
||||||
|
[
|
||||||
|
{ id: 0, value: 'a' },
|
||||||
|
{ id: 1, value: 'b' },
|
||||||
|
{ id: 2, value: 'c' },
|
||||||
|
{ id: 1, value: 'd' },
|
||||||
|
{ id: 0, value: 'e' }
|
||||||
|
],
|
||||||
|
(a, b) => a.id == b.id
|
||||||
|
); // [ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### unzip
|
### unzip
|
||||||
|
|
||||||
Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip).
|
Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip).
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7,7 +7,7 @@ The comparator function takes four arguments: the values of the two elements bei
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const filterNonUniqueBy = (arr, fn) =>
|
const filterNonUniqueBy = (arr, fn) =>
|
||||||
arr.filter((v, i) => arr.every((x, j) => i == j == fn(v, x, i, j)));
|
arr.filter((v, i) => arr.every((x, j) => (i == j) == fn(v, x, i, j)));
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -17,7 +17,7 @@ filterNonUniqueBy(
|
|||||||
{ id: 1, value: 'b' },
|
{ id: 1, value: 'b' },
|
||||||
{ id: 2, value: 'c' },
|
{ id: 2, value: 'c' },
|
||||||
{ id: 1, value: 'd' },
|
{ id: 1, value: 'd' },
|
||||||
{ id: 0, value: 'e' },
|
{ id: 0, value: 'e' }
|
||||||
],
|
],
|
||||||
(a, b) => a.id == b.id
|
(a, b) => a.id == b.id
|
||||||
); // [ { id: 2, value: 'c' } ]
|
); // [ { id: 2, value: 'c' } ]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ uniqueElementsBy(
|
|||||||
{ id: 1, value: 'b' },
|
{ id: 1, value: 'b' },
|
||||||
{ id: 2, value: 'c' },
|
{ id: 2, value: 'c' },
|
||||||
{ id: 1, value: 'd' },
|
{ id: 1, value: 'd' },
|
||||||
{ id: 0, value: 'e' },
|
{ id: 0, value: 'e' }
|
||||||
],
|
],
|
||||||
(a, b) => a.id == b.id
|
(a, b) => a.id == b.id
|
||||||
); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]
|
); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ uniqueElementsByRight(
|
|||||||
{ id: 1, value: 'b' },
|
{ id: 1, value: 'b' },
|
||||||
{ id: 2, value: 'c' },
|
{ id: 2, value: 'c' },
|
||||||
{ id: 1, value: 'd' },
|
{ id: 1, value: 'd' },
|
||||||
{ id: 0, value: 'e' },
|
{ id: 0, value: 'e' }
|
||||||
],
|
],
|
||||||
(a, b) => a.id == b.id
|
(a, b) => a.id == b.id
|
||||||
); // [ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ]
|
); // [ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ]
|
||||||
|
|||||||
Reference in New Issue
Block a user