1.1 KiB
1.1 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| a302f7aae1aa3152a5b413bc | 计算整数的阶乘 | 5 | 16013 | factorialize-a-number |
--description--
返回一个给定整数的阶乘计算结果。
对于整数 n,n 的阶乘就是所有小于等于 n 的正整数的乘积。
阶乘通常用符号 n! 来表示。
例如:5! = 1 * 2 * 3 * 4 * 5 = 120
在这个挑战中,只有非负整数会作为参数传入函数。
--hints--
factorialize(5) 应返回一个数字。
assert(typeof factorialize(5) === 'number');
factorialize(5) 应该返回 120。
assert(factorialize(5) === 120);
factorialize(10) 应该返回 3628800。
assert(factorialize(10) === 3628800);
factorialize(20) 应该返回 2432902008176640000。
assert(factorialize(20) === 2432902008176640000);
factorialize(0) 应该返回 1。
assert(factorialize(0) === 1);
--seed--
--seed-contents--
function factorialize(num) {
return num;
}
factorialize(5);
--solutions--
function factorialize(num) {
return num < 1 ? 1 : num * factorialize(num - 1);
}
factorialize(5);