Problem 43
Count Nested Arrays Recursion Challenge
Given an array, return the total number of arrays nested inside it at any depth. Do not count the outermost input array itself.
Function Signature
countNestedArrays(array)
Parameters
array— an array that may contain values or nested arrays.
Output
Return a number representing the count of all nested arrays (excluding the input array).
Constraints
- The function must use recursion.
- The input array must not be mutated.
- The function should accept exactly one argument.
Examples
countNestedArrays([]) → 0
countNestedArrays([1, 2, 3]) → 0
countNestedArrays([1, [2], [3, [4]], 5]) → 3
countNestedArrays([[], [[]], [[[]]]]) → 6