← Back to challenges

Recursion: Array Sum

JavaScriptHardrecursionnumbersarrayslanguage_fundamentals

Instructions

Write a function that finds the sum of an array. Make your function recursive.

Examples

sum([1, 2, 3, 4]) ➞ 10

sum([1, 2]) ➞ 3

sum([1]) ➞ 1

sum([]) ➞ 0

Notes

  • Return 0 for an empty array.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Smash Factor