Skip to content

Instantly share code, notes, and snippets.

@thomasnorris
Created November 24, 2021 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasnorris/43507acf6bdd0bb4300ff294bd44f3ef to your computer and use it in GitHub Desktop.
Save thomasnorris/43507acf6bdd0bb4300ff294bd44f3ef to your computer and use it in GitHub Desktop.
// returns grouping of arr by key
let groupBy = function(arr, key) {
return arr.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment