I'm strugguling with Javascript on how to find all combinations of an array source with n depth that is broken into sections (0, 1, & 2 in example below). I want to end up with each possible cominbation - and each returned array should include one and only one value from each group. I've hardcoded a solution to 4 levels, but need more flexibility - the flexibility that recursion provides. I've reviewed lots of possible recursive solutions, and while I understand how those work I just can't figure out how to get this particular source data to work.
sourceArr=[
[0,60,100]
,[0,60,200]
,[0,66,300]
,[1,69,500]
,[2,70,600]
,[2,70,700]
,[2,77,800]
,[2,77,900]
]
Intended return value...
[
[{60,100],{69,500},{70,600}]
,[{60,100],{69,500},{70,700}]
,[{60,100],{69,500},{77,800}]
,[{60,100],{69,500},{77,900}]
,[{60,200],{69,500},{70,600}]
,[{60,200],{69,500},{70,700}]
,[{60,200],{69,500},{77,800}]
,[{60,200],{69,500},{77,900}]
,[{66,300],{69,500},{70,600}]
,[{66,300],{69,500},{70,700}]
,[{66,300],{69,500},{77,800}]
,[{66,300],{69,500},{77,900}]
]