I see that you don’t understand the definition of “recursion”, but that is totally fine.
Recursion :
(1) it’s a recursive function calls itself.
example: function countdown(num){ …countdown(num-1);}
(2) it’s recursive function that needs 2 main paths.
-(a) a base case: a terminating condition
-(b) a recursive part: the main part
So with this question, let’s find the base case first
function sum(arr, n) {
if(n <= 0) { //This is the base case, n needs to be greater than 0
return 0; //So when n is no longer greater than 0, please terminate it and return 0.
} else {
/*Now, let's write the recursive part!
But first thing first, We need to know that computer counts array from 0.
Therefore, when n=3 means that we count the index of array till (3-1).
Here we start with the first one arr[n-1] , and then we can call the function itself sum(arr, n-1). Continue repeating it till the base case happens.
The result will be arr[n-1] + arr[n-1-1]+ arr[n-1-1-....]+ arr[n-n]*/
return arr[n - 1] + sum(arr, n - 1) ;
}
}