recursion Compute the sum of an array of integers in Javascript code example
Example: sum numbers recursively js
function sum(n) {
if (n < 1) return 0; // exit condition
return n + sum(n - 1); // return value plus result of recursive call
}
console.log(sum(3));