Solving Factorials Recursively
A factorial is a non-negative integer, which is the product of all the positive integers less than or equal to itself. So, for example, the factorial of 5 is 120 (5 * 4 * 3 * 2 * 1). The factorial of 0 is always 1.
Without using recursion, we would calculate the factorial as follows in Ruby:
Now, here is the factorial method using recursion:
So how does the recursive method work? I found it useful to draw it out…