Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.JS Sugar Cartesian Product
require('sugar');
export.product = function(){
var pools = Array.create(arguments);
return pools.reduce(function(accumulated, next){
return accumulated.map(function(prefix){
return next.map(function(suffix){
return prefix.concat([suffix]);
});
}).flatten(1);
}, [[]]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.