Created
May 7, 2018 22:54
-
-
Save adrianhorning08/d688fc9bc4ca4ef4e6b66a2f3a0268a8 to your computer and use it in GitHub Desktop.
Cartesian product of multiple arrays
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 printCombos(array) { | |
var results = [[]]; | |
for (var i = 0; i < array.length; i++) { | |
var currentSubArray = array[i]; | |
var temp = []; | |
for (var j = 0; j < results.length; j++) { | |
for (var k = 0; k < currentSubArray.length; k++) { | |
temp.push(results[j].concat(currentSubArray[k])); | |
} | |
} | |
results = temp; | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment