Format snippets
This commit is contained in:
@ -10,10 +10,12 @@ Groups the elements of an array based on the given function.
|
||||
|
||||
```js
|
||||
const groupBy = (arr, fn) =>
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
||||
acc[val] = (acc[val] || []).concat(arr[i]);
|
||||
return acc;
|
||||
}, {});
|
||||
arr
|
||||
.map(typeof fn === 'function' ? fn : val => val[fn])
|
||||
.reduce((acc, val, i) => {
|
||||
acc[val] = (acc[val] || []).concat(arr[i]);
|
||||
return acc;
|
||||
}, {});
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user