Skip to content

Instantly share code, notes, and snippets.

@w33ble
Created March 16, 2017 18:37
Show Gist options
  • Save w33ble/e600dfdb4675437854bf037fa0942746 to your computer and use it in GitHub Desktop.
Save w33ble/e600dfdb4675437854bf037fa0942746 to your computer and use it in GitHub Desktop.
to _.groupBy, or not to _.groupBy
const docTypes = _.groupBy(docs, doc => {
switch (doc._type) {
case 'search':
return 'searches'
default:
return 'other'
}
});
const docTypes = docs.reduce((types, doc) => {
switch (doc._type) {
case 'search':
types.searches.push(doc);
break;
default:
types.other.push(doc);
}
return types;
}, {
searches: [],
other: [],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment