Calculate Depth of Array

Published by Helen Yu in

Given an array, write a function to calculate it's depth. Assume that a normal array has a depth of 1.

Examples

depth([1, 2, 3, 4]) ➞ 1

depth([1, [2, 3, 4]]) ➞ 2

depth([1, [2, [3, 4]]]) ➞ 3

depth([1, [2, [3, [4]]]]) ➞ 4

Notes

N/A

Watch a quick demo on how Edabit works.