0

I have many arrays like these, the amounts are dynamic, can be 3, 10, 35 and so on...

[1, 2, 3, 4, 5]
[1, 2, 3]
[1, 2, 3, 4]
...
...

Then I want to create a combination value out of them like these:

[
111, // combine from: first arr idx 0, second arr idx 0, third arr idx 0
112, // idx 0, idx 0, idx 1
113,
114
]

[
121, // idx 0, idx 1, idx 0
122,
123,
124 // idx 0, idx 1, idx 3
]

[131, 132, 133, 134]

[
211,  // idx 1, idx 0, idx 0
212,
213,
214
]

[221, 222, 223, 224]
...
...

If the amounts of source arrays are static, lets say always 3, it can be easily to accomplish by using nested for loop.

But I am struggling to solve this because they are dynamic, sometimes just 2 arrays and other time can be 15 arrays.

Note that the integer values are just examples, I should've used string.

ranusharao
  • 1,826
  • 1
  • 8
  • 17
Bens
  • 831
  • 4
  • 12
  • 28
  • I have reopened the question. But, the approach is similar: [Cartesian product of multiple arrays in JavaScript](https://stackoverflow.com/questions/12303989) – adiga Oct 10 '19 at 17:45
  • @adiga thanks, yeah the question right there is exactly similar to mine – Bens Oct 10 '19 at 17:58
  • It's not exactly the same because you have one more level of grouping. – adiga Oct 10 '19 at 18:09

0 Answers0