Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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));
 
PREVIOUS NEXT
Tagged: #sum #numbers #recursively #js
ADD COMMENT
Topic
Name
6+9 =