According to Wikipedia, the factorial of a positive integer n (denoted by n!) is the product of all positive integers less than or equal to n.
For example, 5! = 5 x 4 x 3 x 2 x 1 = 120.
The value of 0! is 1.
Time Taken: 51 ms
Here is the factorial function coded to be called recursively:
Time Taken: 165 ms
We can speed up the recursive function with the use of memoization. Hence, if the value has previously been computed, it is simply returned and the recursive call ends.
Time Taken: 17 ms