Skip to content

Instantly share code, notes, and snippets.

@ozzyr
Forked from suissa/groupBy.js
Created June 29, 2020 15:25
Show Gist options
  • Save ozzyr/3ff7cbeb756d878404f3fbf9fc04c3d3 to your computer and use it in GitHub Desktop.
Save ozzyr/3ff7cbeb756d878404f3fbf9fc04c3d3 to your computer and use it in GitHub Desktop.
Group by bem facinho
const groupBy = (xs, key) => xs.reduce((rv, x) => ({
...rv, [x[key]]: [...(rv[x[key]] || []), x]
}), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment