I would like to generate all permutations of elements in a multi array in javascript (or the algorithm):
Input:
[
['a', 'b', 'c', 'd'],
['e', 'f', 'g'],
['h', 'i']
]
Output:
[
['a', 'e', 'h'],
['a', 'e', 'i'],
['a', 'f', 'h'],
...
['d', 'g', 'i']
]
Note: I don't want the permutations of ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] because i don't want results like: ['a', 'b', 'c'].
Note2: I'm only interested in solutions that support input of N-dimension array.
Thanks!