Skip to content

Instantly share code, notes, and snippets.

@eberlitz
Created August 5, 2016 16:39
Show Gist options
  • Save eberlitz/c289c7daa9f5f07b0110779b8747bdbf to your computer and use it in GitHub Desktop.
Save eberlitz/c289c7daa9f5f07b0110779b8747bdbf to your computer and use it in GitHub Desktop.
Underscore Unwind like MongoDB operation
_.mixin({
unwind: function(arr, field) {
return _.flatten(_.map(arr, function(o) {
return _.map(o[field], function(val) {
var cloned = _.clone(o);
cloned[field] = val;
return cloned;
});
}));
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment