Depth-first combination algorithm
问题 Let's say I have the following array of arrays: A = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h'], ['i'], ['j', 'k', 'l'] ] I want to find all possible combinations of the elements of each array with the elements of the other arrays (i.e. 'adgij' is one possibility but not 'abcde'). I can brute force it and just loop everything like this (javascript): var A = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h'], ['i'], ['j', 'k', 'l'] ], combinations, newCombinations = []; A.forEach(function(a,