function factorial(n, total) {
if (n === 1) return total;
return factorial(n - 1, n * total);
}
console.log( factorial(5, 1)); // 120
用递归求n阶乘
最新推荐文章于 2023-01-19 17:59:10 发布
function factorial(n, total) {
if (n === 1) return total;
return factorial(n - 1, n * total);
}
console.log( factorial(5, 1)); // 120