So after the update I actually understand the problem.
As for the solution. I think a recursive approach would be best here. I’ll just give the pseudocode and leave implementation up to you:
function getAllCombinations( inputArr ) {
if inputArr has just one element {
return a list with all possible values
}
first = get the first element of the input array
newInput = inputArr with the first element removed
subResult = getAllCombinations( newInput )
result = empty list
for each possible value for the first element of the result as newElement
(can be enumerated by using first) {
combine newElement with subResult and put in result
}
return result
}
So the idea behind is, take the first element out of the input, recursively generate all solutions for the smaller input. Afterwards combine the solutions with all possible elements resulting from the first element.
Base case is, when the input array has just one element. Here the answer is a list of all possible values for that cell.
1
solved How could I use JS to transform given array to other arrays? [closed]