2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: a302f7aae1aa3152a5b413bc
|
2021-02-06 04:42:36 +00:00
|
|
|
title: Factorialize a Number
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 5
|
2021-01-12 16:18:51 +00:00
|
|
|
forumTopicId: 16013
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: factorialize-a-number
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Return the factorial of the provided integer.
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Factorials are often represented with the shorthand notation `n!`
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
For example: `5! = 1 * 2 * 3 * 4 * 5 = 120`
|
2021-01-12 16:18:51 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Only integers greater than or equal to zero will be supplied to the function.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`factorialize(5)` should return a number.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(typeof factorialize(5) === 'number');
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`factorialize(5)` should return 120.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(factorialize(5) === 120);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`factorialize(10)` should return 3628800.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(factorialize(10) === 3628800);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`factorialize(20)` should return 2432902008176640000.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(factorialize(20) === 2432902008176640000);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`factorialize(0)` should return 1.
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(factorialize(0) === 1);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function factorialize(num) {
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
factorialize(5);
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```js
|
|
|
|
function factorialize(num) {
|
|
|
|
return num < 1 ? 1 : num * factorialize(num - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
factorialize(5);
|
|
|
|
```
|