Problem 5

Sum Below Recursion Challenge

Given an integer n, return the sum of all integers between zero and n, exclusive of n itself. For negative values of n, sum the negative integers between n and zero.

Function Signature

sumBelow(n)

Parameters

  • n — an integer, which may be positive, negative, or zero.

Output

Return a number representing the sum of all integers between zero and n (not including n).

Constraints

  • The function must use recursion.
  • The function should accept exactly one argument.

Examples

sumBelow(0)   → 0
sumBelow(1)   → 0
sumBelow(2)   → 1
sumBelow(7)   → 21    (1 + 2 + 3 + 4 + 5 + 6)
sumBelow(10)  → 45
sumBelow(-1)  → 0
sumBelow(-6)  → -15   (-1 + -2 + -3 + -4 + -5)