📜  递归地求和数字js - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:25.694000             🧑  作者: Mango

代码示例2
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));