update snippets 47-62

This commit is contained in:
Stefan Feješ
2017-12-25 14:16:05 +01:00
parent 7b9ec970e2
commit 16b3984591
15 changed files with 64 additions and 22 deletions

View File

@ -9,6 +9,9 @@ Use `Array.reduce()` to create an object, where the keys are produced from the m
const groupBy = (arr, func) =>
arr.map(typeof func === 'function' ? func : val => val[func])
.reduce((acc, val, i) => { acc[val] = (acc[val] || []).concat(arr[i]); return acc; }, {});
// groupBy([6.1, 4.2, 6.3], Math.floor) -> {4: [4.2], 6: [6.1, 6.3]}
// groupBy(['one', 'two', 'three'], 'length') -> {3: ['one', 'two'], 5: ['three']}
```
```js
groupBy([6.1, 4.2, 6.3], Math.floor) -> {4: [4.2], 6: [6.1, 6.3]}
groupBy(['one', 'two', 'three'], 'length') -> {3: ['one', 'two'], 5: ['three']}
```