Travis build: 790 [ci skip]

This commit is contained in:
Travis CI
2018-01-01 15:14:04 +00:00
parent ff6caf7b38
commit 6a34fd1ef3
3 changed files with 82 additions and 86 deletions

104
README.md
View File

@ -63,6 +63,7 @@
* [`pullAtIndex`](#pullatindex)
* [`pullAtValue`](#pullatvalue)
* [`quickSort`](#quicksort)
* [`reducedFilter`](#reducedfilter)
* [`remove`](#remove)
* [`sample`](#sample)
* [`sampleSize`](#samplesize)
@ -271,15 +272,6 @@
</details>
### _Uncategorized_
<details>
<summary>View contents</summary>
* [`reducedFilter`](#reducedfilter)
</details>
---
## 🔌 Adapter
@ -1192,6 +1184,48 @@ quickSort([4, 1, 3, 2], true); // [4,3,2,1]
<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
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.
```js
const isArrayLike = val =>
try {return [...val], true; }
catch (e) { return false; }
const isArrayLike = val => {
try {
return [...val], true;
} catch (e) {
return false;
}
};
```
@ -4713,45 +4746,6 @@ yesNo('Foo', true); // true
<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

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,11 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
```js
const isArrayLike = val => {
try {return [...val], true; }
catch (e) { return false; }
try {
return [...val], true;
} catch (e) {
return false;
}
};
```