Recursion: Sum

Published by mqqqqqx in

Write a function that recursively finds the sum of the first n natural numbers.

Examples

Sum(5) ➞ 15
// 1 + 2 + 3 + 4 + 5 = 15

Sum(1) ➞ 1

Sum(12) ➞ 78

Notes

  • Assume the input number is always positive.
  • Check the Resources tab for info on recursion.
Watch a quick demo on how Edabit works.