Files
30-seconds-of-code/test/groupBy/groupBy.js
2018-01-09 06:09:49 -05:00

5 lines
183 B
JavaScript

module.exports = (arr, func) =>
arr.map(typeof func === 'function' ? func : val => val[func]).reduce((acc, val, i) => {
acc[val] = (acc[val] || []).concat(arr[i]);
return acc;
}, {});