代码1:function factorialize1(num) { if(num === 0){ return 1; } return num * factorialize1(num-1) ;}console.time('text1');factorialize1(100);console.timeEnd('text1');//需要回车后才能显示结果,这样测试时间就不准确,而且相差很多代码2:function factorialize2(n, total = 1) { if (n === 1) return total; return factorialize2(n - 1, n * total);}console.time('text2');factorialize2(100);console.timeEnd('text2');
1 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
function factorialize2(n, total = 1) {
if (n === 1) return total;
return factorialize2(n - 1, n * total);
}
console.time('text2');factorialize2(100);console.timeEnd('text2');
添加回答
举报
0/150
提交
取消