Skip to content

Instantly share code, notes, and snippets.

View masterbraintesting's full-sized avatar

masterbraintesting

View GitHub Profile
@masterbraintesting
masterbraintesting / object-group-by.js
Created July 11, 2025 23:45 — forked from gtrabanco/object-group-by.js
Object.groupBy polyfill
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;
}, {});
};