代码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');
慕工程0101907
相关分类