Write sumNested(items) that adds up every number inside items, no matter how deeply the arrays are nested.
- Each element of
itemsis either a number or another array of the same shape. - Empty arrays add nothing. An empty
itemsreturns0. - Numbers can be negative.
- Don't use
.flat()orJSON.stringify. Handle the nesting yourself:sumNestedshould call itself on the inner arrays.
Input: items = [1, [2, 3], [[4]]]
Output: 10
Input: items = [5, [], [-2, [1, [1]]]]
Output: 5
Input: items = []
Output: 0