Exercises
The following exercises provide you with the opportunity to practice with recursion. The solutions to these exercises are found in the section Chapter 11.
-
Use recursion to write a function that accepts an array of strings and returns the total number of characters across all the strings. For example, if the input array is ["ab", "c", "def", "ghij"], the output should be 10 since there are ten characters in total.
-
Use recursion to write a function that accepts an array of numbers and returns a new array containing just the even numbers.
-
A particular numerical sequence is known as triangular numbers. The pattern begins as 1, 3, 6, 10, 15, 21, and continues onward. To calculate the next number in the sequence, we add the previous number ...
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