Loading...
intermediate
Problem 06 • Step 05
sum-to
sum-to adds up all numbers from 1 to n:
sum-to(0)= 0sum-to(4)= 4 + 3 + 2 + 1 + 0 = 10
You wrote factorial in the recursion problem. sum-to has the same shape — one base case, one recursive case. The only difference is the operation: addition instead of multiplication, and a different base case value.
If you wrote factorial as a lambda with an if that checks n == 0, you already know the structure. What changes is what you return in each branch.