Determine the depth of an array A simple challenge for your Monday evening (well, or Tuesday morning in the other half of the world...)

You're given as input a nested, potentially ragged array of positive integers:

[1, [[2, 3, [[4], 5], 6, [7, 8]], 9, [10, [[[11]]]], 12, 13], 14]


Your task is to determine its depth, which is the greatest nesting-depth of any integer in the list. In this case, the depth of 11 is 6, which is largest.

You may assume that none of the arrays will be empty.

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.

Input may be taken in any convenient list or string format that supports non-rectangular arrays (with nested arrays of different depths), as long as the actual information isn't preprocessed.

You must not use any built-ins related to the shape of arrays (including built-ins that solve this challenge, that get you the dimensions of a nested array). The only exception to this is getting the length of an array.

Standard code-golf rules apply.

Test Cases

[1]                                                               -&gt; 1
[1, 2, 3]                                                         -&gt; 1
[[1, 2, 3]]                                                       -&gt; 2
[3, [3, [3], 3], 3]                                               -&gt; 3
[[[[1], 2], [3, [4]]]]                                            -&gt; 4
[1, [[3]], [5, 6], [[[[8]]]], 1]                                  -&gt; 5
[1, [[2, 3, [[4], 5], 6, [7, 8]], 9, [10, [[[11]]]], 12, 13], 14] -&gt; 6
[[[[[[[3]]]]]]]                                                   -&gt; 7
K, 4 bytes

#,/\


In K, ,/ will join all the elements of a list. The common idiom ,// iterates to a fixed point, flattening an arbitrarily nested list completely. ,/\ will iterate to a fixed point in a similar way, but gather a list of intermediate results. By counting how many intermediate results we visit before reaching the fixed point (#), we get the answer we want: the maximum nesting depth.

"Count of join over fixed-point scan".

In action:

 (#,/\)'(,1
        1 2 3
        ,1 2 3
        (3;(3;,3;3);3)
        ,((,1;2);(3;,4)))
1 1 2 3 4