Created
August 22, 2015 20:34
-
-
Save Alphadelta14/87aea1832deeebaa0340 to your computer and use it in GitHub Desktop.
Node.JS Sugar Cartesian Product
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
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