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/58ba0b073bf098a1ac4eda4fca0d633a to your computer and use it in GitHub Desktop.
Save ozzyr/58ba0b073bf098a1ac4eda4fca0d633a 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