Let’s pretend I have the following lists:
const list1 = [1,2,3,4,5]
const list2 = [6,7,8,9,10]
const list3 = [11,12,13,14,15]
const list4 = [16,17,18,19,20]
How do I get all possible combinations but only with different indexes?
So for example the result [1,6,11,16]
wouldn’t work.
I would need all combinations like:
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 10],
[1, 2, 3, 9, 5].
[1, 2, 3, 9, 10],
[1, 2, 8, 4, 5],
[1, 2, 8, 9, 5],
[1, 2, 8, 4, 10],
[1, 2, 8, 9, 10],
...
[6, 2, 3, 4, 5],
[6, 2, 13, 14, 20]
and so on…
So index of each list, must only be used once.
You can’t use value of list1[0] and of another list index[0].
2
Answers
one way I can think of is like this to generate possible combination
This appears to solve what you want.
Edit: if you also need to associate each value with the list it comes from, I would use a mapper function as follow: