Skip to content
On this page

Factorial

The factorial of a non-negative integer n is the product of all positive integers less than or equal to n. The factorial of n is denoted by n! and is defined as:

n! = n.(n-1).(n-2)...1

The factorial of 0 is defined to be 1.

Usage

js
import { factorial } from "dsacjs";

console.log(factorial(5)); // 120

Complexity

  • Time complexity: O(n)

References