Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Sum of Nested Arrays

Working With Arraysmedium

Course · Section 11: Working With Arrays · Lecture 156: Data Transformations: map, filter, reduce

Implement `sumNested(arrs)` returning the total of all numbers across an array of number arrays, using `reduce`.

Sample tests

Input: sumNested([[1,2],[3],[4,5]])
Output: 15
Input: sumNested([[]])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Forgetting the inner reduce, trying to add arrays directly.

Learning resources

  • MDN: Array.prototype.reduce
Approach & explanation (try first)

An outer reduce accumulates the sum of each inner array's own reduce.

Loading...
⌘/Ctrl + Enter

Run your code to see results.