Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.1 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a302f7aae1aa3152a5b413bc 计算整数的阶乘 5 16013 factorialize-a-number

--description--

返回一个给定整数的阶乘计算结果。

对于整数 nn 的阶乘就是所有小于等于 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);