Travis build: 110
This commit is contained in:
@ -7,18 +7,18 @@ The comparator function takes four arguments: the values of the two elements bei
|
||||
|
||||
```js
|
||||
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
|
||||
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: 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' } ]
|
||||
```
|
||||
|
||||
@ -7,21 +7,21 @@ The comparator function takes two arguments: the values of the two elements bein
|
||||
|
||||
```js
|
||||
const uniqueElementsBy = (arr, fn) =>
|
||||
arr.reduce((acc, v) => {
|
||||
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||
return acc;
|
||||
}, []);
|
||||
arr.reduce((acc, v) => {
|
||||
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||
return acc;
|
||||
}, []);
|
||||
```
|
||||
|
||||
```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' },
|
||||
{ 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' } ]
|
||||
```
|
||||
|
||||
@ -7,21 +7,21 @@ The comparator function takes two arguments: the values of the two elements bein
|
||||
|
||||
```js
|
||||
const uniqueElementsByRight = (arr, fn) =>
|
||||
arr.reduceRight((acc, v) => {
|
||||
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||
return acc;
|
||||
}, []);
|
||||
arr.reduceRight((acc, v) => {
|
||||
if (!acc.some(x => fn(v, x))) acc.push(v);
|
||||
return acc;
|
||||
}, []);
|
||||
```
|
||||
|
||||
```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: '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' } ]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user