Travis build: 790 [ci skip]
This commit is contained in:
104
README.md
104
README.md
@ -63,6 +63,7 @@
|
|||||||
* [`pullAtIndex`](#pullatindex)
|
* [`pullAtIndex`](#pullatindex)
|
||||||
* [`pullAtValue`](#pullatvalue)
|
* [`pullAtValue`](#pullatvalue)
|
||||||
* [`quickSort`](#quicksort)
|
* [`quickSort`](#quicksort)
|
||||||
|
* [`reducedFilter`](#reducedfilter)
|
||||||
* [`remove`](#remove)
|
* [`remove`](#remove)
|
||||||
* [`sample`](#sample)
|
* [`sample`](#sample)
|
||||||
* [`sampleSize`](#samplesize)
|
* [`sampleSize`](#samplesize)
|
||||||
@ -271,15 +272,6 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### _Uncategorized_
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>View contents</summary>
|
|
||||||
|
|
||||||
* [`reducedFilter`](#reducedfilter)
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## 🔌 Adapter
|
## 🔌 Adapter
|
||||||
|
|
||||||
@ -1192,6 +1184,48 @@ quickSort([4, 1, 3, 2], true); // [4,3,2,1]
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### 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;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```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'}]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### remove
|
### remove
|
||||||
|
|
||||||
Removes elements from an array for which the given function returns `false`.
|
Removes elements from an array for which the given function returns `false`.
|
||||||
@ -4249,13 +4283,12 @@ Checks if the provided argument is array-like (i.e. is iterable).
|
|||||||
Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value.
|
Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
const isArrayLike = val => {
|
||||||
|
try {
|
||||||
|
return [...val], true;
|
||||||
|
} catch (e) {
|
||||||
const isArrayLike = val =>
|
return false;
|
||||||
try {return [...val], true; }
|
}
|
||||||
catch (e) { return false; }
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -4713,45 +4746,6 @@ 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
@ -6,8 +6,11 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const isArrayLike = val => {
|
const isArrayLike = val => {
|
||||||
try {return [...val], true; }
|
try {
|
||||||
catch (e) { return false; }
|
return [...val], true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user