← Back to challenges

Sum of the Items in an Array

JavaScriptHardarrayslanguage_fundamentalsrecursion

Instructions

Create a function that takes an array and returns the sum of all items in the array.

Examples

sumArray([1, 2, 3]) ➞ 6
// 1 + 2 + 3 = 6

sumArray([1, [2, [1]], 3]) ➞ 7
// 1 + 2 + 1 + 3 = 7

Notes

The item in an array can be another array.

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