← Back to challenges

Calculate Depth of Array

JavaScriptHardarraysrecursion

Instructions

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

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.