Created
September 9, 2018 05:45
-
-
Save suissa/521a930d591d390113ad4481b955a524 to your computer and use it in GitHub Desktop.
JavaScript - groupby - filter 09
This file contains 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 toNewGroup = (field) => (result, obj) => ({ | |
...result, | |
[obj[field]]: [...(result[obj[field]] || []), obj] | |
}) | |
const group = (list) => (field) => | |
list.reduce(toNewGroup(field), {}) | |
const groupBy = group(list) | |
console.log(groupBy("level")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment