Created
April 24, 2014 13:42
-
-
Save serefyarar/11255070 to your computer and use it in GitHub Desktop.
Array - Kartezyen
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
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