MCPcopy Create free account
hub / github.com/TheAlgorithms/TypeScript / factorial

Function factorial

maths/factorial.ts:10–16  ·  view source on GitHub ↗
(num: number)

Source from the content-addressed store, hash-verified

8 * @example factorial(3) = 6
9 */
10export const factorial = (num: number): number => {
11 if (num < 0 || !Number.isInteger(num)) {
12 throw new Error('only natural numbers are supported')
13 }
14
15 return num === 0 ? 1 : num * factorial(num - 1)
16}

Callers 2

binomialCoefficientFunction · 0.90
factorial.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected