Recursion: Array Sum

Published by Mubashir Hassan in

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.
  • Check the Resources tab for info on recursion.
Watch a quick demo on how Edabit works.