There are a few simple tricks I use to help simplify the process of creating a recursive function.
Recursion doesn’t have to be difficult. These tricks, not only help you in writing and reasoning about a recursive function, but will also help reduce the complexity of that function.
Start with the exit cases — 01:26
Focus on the individual values and not the whole structure – 02:32
Write the towards the bottom — 04:40
As a BONUS, the Runkit also includes an example replacing the for loop with reduce
Runkit: https://runkit.com/joelnet/5f1344792ad936001ad53c94