// 求阶乘 例如 5! function factorial(n) { return n<1 ? 1 : n*factorial(n-1) } console.log(factorial(4)); // 阶乘之和 function getSum(n) { let sum = 0 for(var i =1;i<=n;i++){ sum = sum+factorial(i) } return sum } console.log(getSum(5));