Travis build: 1211

This commit is contained in:
30secondsofcode
2018-01-12 11:57:19 +00:00
parent bd8551d78a
commit 72957f37e6
3 changed files with 49 additions and 7 deletions

View File

@ -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.
```js
const transform = (obj, fn, acc) =>
Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
```
```js
transform({ 'a': 1, 'b': 2, 'c': 1 }, (r, v, k) => {
(r[v] || (r[v] = [])).push(k);
return r;
}, {}); // { '1': ['a', 'c'], '2': ['b'] }
transform(
{ a: 1, b: 2, c: 1 },
(r, v, k) => {
(r[v] || (r[v] = [])).push(k);
return r;
},
{}
); // { '1': ['a', 'c'], '2': ['b'] }
```