MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / factorial

Function factorial

Recursive/Factorial.js:11–21  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

9 */
10
11const factorial = (n) => {
12 if (!Number.isInteger(n) || n < 0) {
13 throw new RangeError('Input should be a non-negative whole number')
14 }
15
16 if (n === 0) {
17 return 1
18 }
19
20 return n * factorial(n - 1)
21}
22
23export { factorial }

Callers 3

Memoize.test.jsFile · 0.90
Factorial.test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected