I have an array that looks like this: [0, 1, 2, 3, 4, 5, ...]
I need a function that will give me an array like this:
[
[[0, 1, 2, 3, 4, 5]],
[[0, 1, 2, 3, 4], [ 5 ]],
[[0, 1, 2, 3], [ 4, 5 ]],
[[0, 1, 2], [ 3, 4, 5 ]],
...
[[0, 1, 2], [ 3, 4 ], [ 5 ]],
...
[[ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ]]
]
Of course this output is only for 6 elements.
If you look at the 2nd, 3rd and 4th line of the output array, it's some sort of combination into 2 sub-arrays.
If you look at the 6th line of the output array, it becomes into 3 sub-arrays.
In the last line every element should be alone in its own sub-array.
I saw the examples on this page and I tried the functions but mine is a little different because the order of the elements need to be respected. This means that regardless of where the brackets are,
you should see 1 2 3 4 5 6 on each line.
Also, the functions in the previously mentioned page will give me an array including all the sub-arrays:
[[x,x],[x],[x],[xxx]] I can't use this.
What I need is this format:
[
[ [ 1 , 2 , 3 ] ] ,
[ [ 1 , 2 ] , [ 3 ] ] ,
[ [ 1 ] , [ 2 , 3 ] ] ,
[ [ 1 ] , [ 2 ] , [ 3 ] ]
]
I am a beginner, please someone give me a hint on how to do this!
See Question&Answers more detail:
os