Solution Review: The Factorial of a Number
This lesson explains the solution for the factorial of a number exercise.
We'll cover the following...
Solution
Press + to interact
let rec fact = (n: int) => {/* Check if n is 0 or 1 */switch (n) {| 0 => 1; /* Base case */| n => n * fact(n - 1) /* Make recursive calls and multiply each time */};};Js.log(fact(5));
Explanation
This problem can be solved easily using ...