题解 | #阶乘#
阶乘
http://www.nowcoder.com/practice/39fcf876fab34fe8afc298de10a1e112
1.循环实现
// for循环
function _factorial(number) {
// 补全代码
let res = 1;
for(let i=1;i<=number;i++) {
res *=i;
}
return res;
}
// while循环
function _factorial(number) {
// 补全代码
let res = 1;
while(number>=1) {
res *=number;
number--;
}
return res;
}