Last active
November 27, 2018 18:41
-
-
Save dklassen/55b3ad41db25a772d8a45896536eaf88 to your computer and use it in GitHub Desktop.
Vanillia GroupBy in Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const groupBy = (data, key) => { | |
| return data.reduce( | |
| (acc, cur) => { | |
| const value = acc[cur[key]] ? acc[cur[key]] : [] | |
| value.push(cur); | |
| acc[cur[key]] = value; | |
| return acc; | |
| }, {}); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment