Step one- write ‘if’ a. There must be two cases: a recursive case (where the method calls itself) b. and a base case (where the method does not)
- Handle the simplest case(s). a. Simplest = no recursive call needed (no looping)
- Write the recurisve call(s) a. On the next simplest input/state
- Assume the recursive call works (maybe store the result in a variable) a. Ask yourself, what does it do? b. How does it help?
n! = n * (n - 1)! -> a recursive definition of factorial
“`ruby def factorial(n) if n == 0
result = factorial(n - 1) #computes n-1 factorial result * n