Recursive Category: Calculations
In the previous section, we discussed the first category of recursive functions—those whose job it is to repeatedly execute a task. For the remainder of this chapter, I’ll elaborate on a second general category: performing a calculation based on a subproblem.
The goal of many functions is to perform a calculation. A function that returns the sum of two numbers, or a function that finds the greatest value within an array, are examples. These functions receive some sort of input and return the result of calculations involving that input.
In Chapter 10, Recursively Recurse with Recursion, we found that one area in which recursion shines is where we need to act on a problem that has an arbitrary number of levels ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access