Simplificate an array Input
An array that can contain arrays or positive, consecutive, ascending integers. The arrays can have any number of arrays inside of them, and so on and so forth. No arrays will be empty.
Output
This array simplificated
How to simplificate an array
We will use the array, [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]] as our example.
First, we check how deep the values are nested. Here are the depths and the numbers at those depths:
0  1
1  2 3 9
2  4 7
3  5 6
5  8

We construct the output array by taking the numbers in the original array, grouping them by how deep they are nested, and then nesting the groups at depths of the original depths of their  elements. Arrange the numbers in ascending order and ascending depth.
So, our output is [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]
Examples
[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]] -&gt; [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]
[[[1]], [2, [3]], 4, [5, [6, [7, [8], [9, [[10]]]]]]] -&gt; [4, [2, 5], [[1, 3, 6]], [[[7]]], [[[[8, 9]]]], [[[[[[10]]]]]]]
[1] -&gt; [1]
[1, [2], [[3]], [[[4]]], [[[[5]]]]] -&gt; [1, [2], [[3]], [[[4]]], [[[[5]]]]]
[1, [[[[2], 3]]], [[4]]] -&gt; [1, [[4]], [[[3]]], [[[[2]]]]]
Perl, 52 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}


Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8


Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval (inside @{ } to transform the input into an array and not an arrayref) to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}f(@{+eval})' &lt;&lt;&lt; "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"




My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :


perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' &lt;&lt;&lt; "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"