Travis build: 788 [ci skip]
This commit is contained in:
49
README.md
49
README.md
@ -271,6 +271,15 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
### _Uncategorized_
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`reducedFilter`](#reducedfilter)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
---
|
---
|
||||||
## 🔌 Adapter
|
## 🔌 Adapter
|
||||||
|
|
||||||
@ -4243,6 +4252,7 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
try {return [...val], true; }
|
try {return [...val], true; }
|
||||||
catch (e) { return false; }
|
catch (e) { return false; }
|
||||||
@ -4703,6 +4713,45 @@ yesNo('Foo', true); // true
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
---
|
||||||
|
## _Uncategorized_
|
||||||
|
|
||||||
|
### reducedFilter
|
||||||
|
|
||||||
|
Filter an array of objects based on a condition while also filtering out unspecified keys.
|
||||||
|
|
||||||
|
Use `Array.filter()` to filter the array based on the predicate `fn` so that it returns the objects for which the condition returned a truthy value.
|
||||||
|
On the filtered array, use `Array.map()` to return the new object using `Array.reduce()` to filter out the keys which were not supplied as the `keys` argument.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const reducedFilter = (data, keys, fn) =>
|
||||||
|
data.filter(fn).map(el =>
|
||||||
|
keys.reduce((acc, key) => {
|
||||||
|
acc[key] = el[key];
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'john',
|
||||||
|
age: 24
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: 'mike',
|
||||||
|
age: 50
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
reducedFilter(data, ['id', 'name'], item => item.age > 24); // [{ id: 2, name: 'mike'}]
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
## Collaborators
|
## Collaborators
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -8,6 +8,7 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
try {return [...val], true; }
|
try {return [...val], true; }
|
||||||
catch (e) { return false; }
|
catch (e) { return false; }
|
||||||
|
|||||||
@ -115,6 +115,7 @@ randomIntegerInRange:math
|
|||||||
randomNumberInRange:math
|
randomNumberInRange:math
|
||||||
readFileLines:node
|
readFileLines:node
|
||||||
redirect:browser
|
redirect:browser
|
||||||
|
reducedFilter:uncategorized
|
||||||
remove:array
|
remove:array
|
||||||
repeatString:string
|
repeatString:string
|
||||||
reverseString:string
|
reverseString:string
|
||||||
|
|||||||
Reference in New Issue
Block a user