Skip to content

Instantly share code, notes, and snippets.

@ruffle1986
Created March 10, 2015 13:55
Show Gist options
  • Save ruffle1986/e5e33b6f530c8c77d8ce to your computer and use it in GitHub Desktop.
Save ruffle1986/e5e33b6f530c8c77d8ce to your computer and use it in GitHub Desktop.
Cartesian Product of Arrays
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