Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

1.1 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a302f7aae1aa3152a5b413bc 計算整數的階乘 5 16013 factorialize-a-number

--description--

返回一個給定整數的階乘計算結果。

對於整數 nn 的階乘就是所有小於等於 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);