This way is the implement recursion by processing one element at a time with arr[0] + sumArray(arr.slice(1))
function sumArray(arr) {
if (arr.length === 0) {
return 0; // Base case: empty array sums to 0
}
// Recursive case: head + sum of tail
return arr[0] + sumArray(arr.slice(1));
}
console.log(sumArray([1, 2, 3])); // 6