Wondering how to take a nested array such as this:
var arr = [
1,
[
2, 3, 4,
[
5, 6, 7, 8,
[ 9, 10 ],
[ 11, 12 ]
],
[ 13, 14 ]
]
]
And apply a grouping function:
function group(arr) {
}
Such that it converts arr
into the following:
var output = [
[1, 2, 5, 13, 9, 11],
[1, 2, 5, 13, 9, 12],
[1, 2, 5, 13, 10, 11],
[1, 2, 5, 13, 10, 12]
[1, 3, 5, 13, 9, 11],
[1, 3, 5, 13, 9, 12],
[1, 3, 5, 13, 10, 11],
[1, 3, 5, 13, 10, 12],
[1, 3, 6, 13, 9, 11],
[1, 3, 6, 13, 9, 12],
[1, 3, 6, 13, 10, 11],
[1, 3, 6, 13, 10, 12],
[1, 3, 7, 13, 9, 11],
[1, 3, 7, 13, 9, 12],
[1, 3, 7, 13, 10, 11],
[1, 3, 7, 13, 10, 12],
...
[1, 4, 5, 13, 9, 11],
[1, 4, 5, 13, 9, 12],
[1, 4, 5, 13, 10, 11],
[1, 4, 5, 13, 10, 12],
...
]
Basically it flattens the array, or you could say gets every combination of all sub arrays, and returns them in a flat list. Breaking my head on this one.