August 2024
Intermediate to advanced
516 pages
11h 47m
English
The following exercises provide you with the opportunity to practice with recursion. The solutions to these exercises are found in the section Chapter 10.
The following function prints every other number from a low number to a high number. For example, if low is 0 and high is 10, it would print:
| | 0 |
| | 2 |
| | 4 |
| | 6 |
| | 8 |
| | 10 |
Identify the base case in the function:
| | function printEveryOther(low, high) { |
| | if (low > high) { return; } |
| | |
| | console.log(low); |
| | printEveryOther(low + 2, high); |
| | } |
My kid was playing with my computer and changed my factorial function so that it computes factorial based on (number - 2) instead of (number - 1). He also changed number <= 1 to number === 1. Predict what will happen when we run factorial(10) using ...
Read now
Unlock full access