Answer:
function sum(number) {
if (number == 1) {
return 1;
}
return number + sum(number -1);
}
Step-by-step explanation:
This is a recursive function, it means that is a function that calls itself for example: if you call the function with sum(5) the process is :
sum(5)
|______ 5 + sum(4)
|_______ 4 + sum(3)
|______ 3 + sum(2)
|_____2 + sum(1)
|_____ 1
the result is 1+2+3+4+5 = 15