Created
April 15, 2014 09:53
-
-
Save cajones/10718907 to your computer and use it in GitHub Desktop.
Lodash mixin to produce the product of two arrays.
This file contains 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
_.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