Robert Eisele
Engineer, Systems Architect and DBA

Codefights: Factorial

Original Problem

Given integer n, find n!.

Example

For n = 5, the output should be
factorial(n) = 120.

Here 1 * 2 * 3 * 4 * 5 = 120.

Input/Output

  • [time limit] 4000ms (js)
  • [input] integer n

    Constraints:
    0 ≤ n ≤ 10.

  • [output] integer

Solution

_ = factorial = n =>
    n ? n * _(n - 1) : 1

« Back to problem overview