Skip to content

Instantly share code, notes, and snippets.

@koozdra
Created August 19, 2020 20:19
Show Gist options
  • Save koozdra/fe1e41a7fd25661eef800489aeb2991e to your computer and use it in GitHub Desktop.
Save koozdra/fe1e41a7fd25661eef800489aeb2991e to your computer and use it in GitHub Desktop.
key array of objects by multiple keys
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