I need a solution to this problem

Write a recursive function, sum(arr, n) , that returns the sum of the first n elements of an array arr .

function sum(arr, n) {
// Only change code below this line
if (n <= 1) {
return 0;
} else {
return sum(arr, n - 1) + arr[n - 1];
}
// Only change code above this line
}

Hi there,
Did you need to ask something?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.