Skip to content

Instantly share code, notes, and snippets.

@cajones
Created April 15, 2014 09:53
Show Gist options
  • Save cajones/10718907 to your computer and use it in GitHub Desktop.
Save cajones/10718907 to your computer and use it in GitHub Desktop.
Lodash mixin to produce the product of two arrays.
_.mixin({
'combine': function (xArray, yArray, func) {
return xArray.map(function (x) {
return yArray.map(function (y) {
return func(x, y);
});
});
}
});
//usage
var verbs = ['herp', 'derp', 'glerp'];
var endings = [ 'ing', 'ed' ];
var append = function (start, end) { return start + end; });
_(verbs).combine(endings, append).tap(console.log);
// [ [ 'herping', 'herped' ], ['derping', 'derped'], ['glerping', 'glerped'] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment