Recursion is incredibly common everyday life. Most often our brains use recursion to navigate basic tasks without us having to think about it. My favorite example is chewing food - do you chew your food an explicit number of times or do you keep chewing until your brain senses it has been chewed enough to swallow? Because we don't think about recursion explicitly very often it can be difficult to wrap our heads around it.
In programming, a function is considered recursive if it calls itself during execution.
A base case to be met; something that will end the execution. The calling of itself.
Often recursive function are more expressive; they closer resemble how someone would describe a solution in English.
Repeater
Modify the function so that it returns a string containing the input character repeated 5 times. Use recursion!
Is Even
Modify the function so that it returns true if a number is even (and false if it's not). Assume input will be a positive integer. Use recursion!
Factorial
Modify the function so that it returns the factorial of an input number. Use recursion!
The factorial of n is the product of all numbers between 1 and n
Ex: 5! = 5 * 4 * 3 * 2 * 1
Get Length
Modify the function so that it returns the length of an array recursively, without using the .length property. Use recursion!
Hint: What does JavaScript return when you attempt to access an index that is greater than array.length - 1?
POW
Modify the function so that it returns base to the power of exponent. Use recursion!
Ex: pow(5, 3) = 5 * 5 * 5
Flow
Modify the function so that it returns the result of running the input number through each function in funcArray, in order. Use recursion!
First do it recursively, if you have time at the end try using a reduce function
Fibonacci
Modify the function so that it returns the nth Fibonacci number. Try not to look back at the slides!
Fibonacci reference: 1, 1, 2, 3, 5, 8, 13, ...
Heads or Tails
Modify the function so that it returns all possible outcomes of n games of heads or tails as an array of arrays
Combos of Any length
Modify this function so that it returns all combinations of the elements of arr as an array of arrays. Use Recursion!