Created
August 19, 2020 20:19
-
-
Save koozdra/fe1e41a7fd25661eef800489aeb2991e to your computer and use it in GitHub Desktop.
key array of objects by multiple keys
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
a = [ { name: 'bill', group: 'b' }, | |
{ name: 'ann', group: 'a' }, | |
{ name: 'ken', group: 'k' }, | |
{ name: 'alex', group: 'a' } ] | |
_.reduce((sum, v) => { | |
const { name, group } = v; | |
const current = _.getOr([], [group, name])(sum); | |
return _.set([group, name], [...current, v])(sum); | |
}, {})(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment