Measure the Depth of Emptiness

Published by bangyen in

In this challenge you will receive an input of the form:

[[[[[[[[[[[]]]]]]]]]]]

In other words, an array containing an array containing an array containing... an array containing nothing.

Your goal is to measure the depth of this array, where [] has a depth 1, [[]] has depth of 2, [[[]]] has depth 3, etc.

Examples

depth([]) ➞ 1

depth([[]]) ➞ 2

depth([[[]]]) ➞ 3

depth([[[[[[[[[[[]]]]]]]]]]]) ➞ 11

Notes

One way to solve this is with recursion; but maybe there's a way to "count the brackets"?

Watch a quick demo on how Edabit works.