Skip to content
Advertisement

How does the recursion of printNStars work?

I don’t understand the output of this recursion. Can someone please help me? (flowchart will definitely help me understand..)

JavaScript

Output of the code above:

JavaScript

Advertisement

Answer

It works in the following way:

JavaScript

which can be translated into:

JavaScript

there is also an exit rule. If n is 1, don’t draw previous rows. Just print one star.

The executions will be in the following order:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement