So I have a variable length array filled with variable length arrays. Something like this for example:
var arr2d = [
['red', 'blue'],
['cotton','polyester','silk'],
['large','medium','small']
]
I am trying to get all possible combinations of one from each array. so the answer should look something like this:
var answer = [
['red', 'cotton', 'large'],
['red', 'cotton', 'medium'],
['red', 'cotton', 'small'],
['red', 'polyester', 'large'],
.
.
.
]
I've looked into the other answer on this topic but all of them are in java (I need javascript) and they were looking for all combinations and not limited to the combinations of length === arr2d.length
. I've looked at this for almost 2 hours and still I cannot think of a way to do this recursively. It's one of those head explosion scenarios because both the arrays vary in length (I have an array of these 2d arrays that I must get the combinations for). In the example I've laid out there are only 18 possiblities, but in practice it could be thousands.