For example,
[1,2,3,4], [5], [7,8], [9]
Generate a one-dimensional array, which should be 8 types.
In fact, it looks like a branch ~
[1,5,7,9],
[2,5,7,9],
[1,5,7,9],
/***
** Omitted ...
***/
[4,5,8,9]
What if there is one more element?
[1,2,3,4], [5,6], [7,8], [9]
How to list all possible combinations?
4*2*2, 16 kinds.
Permutations and combinations, since each array must have one element, then for
array 1: c(4,1)=4,
array 2: c(2,1) =2,
Array 3: c(2,1)=2,
Array 4: c(1,1)=1,
Multiply each one again and pay attention to repeated elements.
Generally speaking, if there are several groups, several loops are needed. Just combine the elements inside one by one. This is the conventional solution of js. I don’t know if there is a better one.