Compare commits

...

4 Commits

Author SHA1 Message Date
Sanil Surve
2edcaad267
Merge 2208c5415f into 9046d80bdb 2024-07-13 21:08:46 +02:00
Sanil-Surve
2208c5415f Initial commit 2024-06-20 20:02:51 +05:30
Sanil-Surve
39552b63a2 Initial commit 2024-06-20 19:47:01 +05:30
Sanil-Surve
fba0828693 Solved Issue 1008 2024-06-20 19:37:55 +05:30
3 changed files with 40 additions and 2 deletions

View File

@ -8,8 +8,7 @@
**Contributing New Translation** **Contributing New Translation**
- Create new `README.xx-XX.md` file with translation alongside with - Create new `README.xx-XX.md` file with translation alongside with main `README.md` file where `xx-XX` is [locale and country/region codes](http://www.lingoes.net/en/translator/langcode.htm).
main `README.md` file where `xx-XX` is [locale and country/region codes](http://www.lingoes.net/en/translator/langcode.htm).
For example `en-US`, `zh-CN`, `zh-TW`, `ko-KR` etc. For example `en-US`, `zh-CN`, `zh-TW`, `ko-KR` etc.
- You may also translate all other sub-folders by creating - You may also translate all other sub-folders by creating
related `README.xx-XX.md` files in each of them. related `README.xx-XX.md` files in each of them.

View File

@ -0,0 +1,35 @@
# Factorial
_Read this in other languages:_
[_简体中文_](README.zh-CN.md), [_Français_](README.fr-FR.md), [_Türkçe_](README.tr-TR.md), [_ქართული_](README.ka-GE.md), [_Українська_](README.uk-UA.md).
In mathematics, the factorial of a non-negative integer `n`,
denoted by `n!`, is the product of all positive integers less
than or equal to `n`. For example:
```
5! = 5 * 4 * 3 * 2 * 1 = 120
```
| n | n! |
| --- | ----------------: |
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 6 |
| 4 | 24 |
| 5 | 120 |
| 6 | 720 |
| 7 | 5 040 |
| 8 | 40 320 |
| 9 | 362 880 |
| 10 | 3 628 800 |
| 11 | 39 916 800 |
| 12 | 479 001 600 |
| 13 | 6 227 020 800 |
| 14 | 87 178 291 200 |
| 15 | 1 307 674 368 000 |
## References
[Wikipedia](https://en.wikipedia.org/wiki/Factorial)

View File

@ -1,7 +1,11 @@
/** /**
* @param {number} number * @param {number} number
* @return {number} * @return {number}
* @throws {Error} if number is negative
*/ */
export default function factorialRecursive(number) { export default function factorialRecursive(number) {
if (number < 0) {
throw new Error('Factorial is not defined for negative numbers.');
}
return number > 1 ? number * factorialRecursive(number - 1) : 1; return number > 1 ? number * factorialRecursive(number - 1) : 1;
} }