Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Latest commit

 

History

History

factorial

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Factorial

Write a factorial function. factorial(n) = 1 * 2 * ... * n, e. g. factorial(4) = 1 * 2 * 3 * 4 = 24.

You should use recursion instead of loops.

Small hint: absence of return statement guarantees having no loops.

factorial(0); //=> 1
factorial(1); //=> 1
factorial(2); //=> 2
factorial(3); //=> 6
factorial(4); //=> 24
factorial(5); //=> 120
factorial(6); //=> 720
factorial(7); //=> 5040
// ...