Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created January 7, 2019 22:04
Show Gist options
  • Select an option

  • Save sethdavis512/63fb003c0c8aec8254e79118a4e51e53 to your computer and use it in GitHub Desktop.

Select an option

Save sethdavis512/63fb003c0c8aec8254e79118a4e51e53 to your computer and use it in GitHub Desktop.
const groupBy = (array, groupKey) => {
return array.reduce((acc, cur) => {
if (acc[cur[groupKey]]) {
acc[cur[groupKey]].push(cur);
} else {
acc[cur[groupKey]] = [cur];
}
return acc;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment