This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasGroup = typeof Object.groupBy === typeof undefined || typeof Array.groupToMap === typeof undefined || typeof Array.group === typeof undefined; | |
if (!hasGroup) { | |
const groupBy = (arr, callback) => { | |
return arr.reduce((acc = {}, ...args) => { | |
const key = callback(...args); | |
acc[key] ??= [] | |
acc[key].push(args[0]); | |
return acc; | |
}, {}); | |
}; |