Skip to content

Instantly share code, notes, and snippets.

@Alphadelta14
Created August 22, 2015 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alphadelta14/87aea1832deeebaa0340 to your computer and use it in GitHub Desktop.
Save Alphadelta14/87aea1832deeebaa0340 to your computer and use it in GitHub Desktop.
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