Travis build: 1211
This commit is contained in:
30
README.md
30
README.md
@ -272,6 +272,7 @@ average(1, 2, 3);
|
|||||||
* [`select`](#select)
|
* [`select`](#select)
|
||||||
* [`shallowClone`](#shallowclone)
|
* [`shallowClone`](#shallowclone)
|
||||||
* [`size`](#size)
|
* [`size`](#size)
|
||||||
|
* [`transform`](#transform)
|
||||||
* [`truthCheckCollection`](#truthcheckcollection)
|
* [`truthCheckCollection`](#truthcheckcollection)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@ -4230,6 +4231,35 @@ size({ one: 1, two: 2, three: 3 }); // 3
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### transform
|
||||||
|
|
||||||
|
Applies a function against an accumulator and each key in the object (from left to right).
|
||||||
|
|
||||||
|
Use `Object.keys(obj)` to iterate over each key in the object, `Array.reduce()` to call the apply the specified function against the given accumulator.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
transform(
|
||||||
|
{ a: 1, b: 2, c: 1 },
|
||||||
|
(r, v, k) => {
|
||||||
|
(r[v] || (r[v] = [])).push(k);
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
); // { '1': ['a', 'c'], '2': ['b'] }
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### truthCheckCollection
|
### truthCheckCollection
|
||||||
|
|
||||||
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -5,13 +5,16 @@ Applies a function against an accumulator and each key in the object (from left
|
|||||||
Use `Object.keys(obj)` to iterate over each key in the object, `Array.reduce()` to call the apply the specified function against the given accumulator.
|
Use `Object.keys(obj)` to iterate over each key in the object, `Array.reduce()` to call the apply the specified function against the given accumulator.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const transform = (obj, fn, acc) =>
|
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
|
||||||
Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
transform({ 'a': 1, 'b': 2, 'c': 1 }, (r, v, k) => {
|
transform(
|
||||||
|
{ a: 1, b: 2, c: 1 },
|
||||||
|
(r, v, k) => {
|
||||||
(r[v] || (r[v] = [])).push(k);
|
(r[v] || (r[v] = [])).push(k);
|
||||||
return r;
|
return r;
|
||||||
}, {}); // { '1': ['a', 'c'], '2': ['b'] }
|
},
|
||||||
|
{}
|
||||||
|
); // { '1': ['a', 'c'], '2': ['b'] }
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user