Search⌘ K

Understanding a Recursive Problem

Explore how recursive problems are structured and solved in JavaScript by examining patterns that decrease and increase values. Understand base and recursive cases, visualize recursion using stacks and trees, and learn variable tracking techniques to dry run recursive functions effectively.

Understanding the Problem

In the previous lessons, we learned the basic concept of recursion, what it is and when it can be used. Now, we will discuss how recursion works.

Let’s have a look at an example. The code below prints a pattern, that subtracts 55 from the targetNumber until we reach a negative number or 00. Then we add 55 until we reach the targetNumber again.

For example:

If targetNumber =10= 10, then our pattern will be 1010\: ...