Skip to content

Instantly share code, notes, and snippets.

@serefyarar
Created April 24, 2014 13:42
Show Gist options
  • Save serefyarar/11255070 to your computer and use it in GitHub Desktop.
Save serefyarar/11255070 to your computer and use it in GitHub Desktop.
Array - Kartezyen
function cartesianProductOf() {
return Array.prototype.reduce.call(arguments, function(a, b) {
var ret = [];
a.forEach(function(a) {
b.forEach(function(b) {
ret.push(a.concat([b]));
});
});
return ret;
}, [[]]);
}
cartesianProductOf([1, 2], [3, 4], ['a', 'b']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment