Created
March 10, 2015 13:55
-
-
Save ruffle1986/e5e33b6f530c8c77d8ce to your computer and use it in GitHub Desktop.
Cartesian Product of 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
function cartesianProductOf() { | |
return _.reduce(arguments, function(a, b) { | |
return _.flatten(_.map(a, function(x) { | |
return _.map(b, function(y) { | |
return x.concat([y]); | |
}); | |
}), true); | |
}, [ [] ]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment