Teach me "replace loop using recursion" topic

Tell us what’s happening:

Your code so far

function sum(arr, n) {
// Only change code below this line

// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36.

Challenge: Replace Loops using Recursion

Link to the challenge:

function teachRecursion(student, lessons){
  if (student.hasUnderstoodRecursion) {
    return 'Done!'
  } else {
    return teachRecursion(student, lessons+1)

That was a little contrived but illustrates the principle. Recursion is when a function calls itself, until it doesn’t (because the condition that stops the function calls was finally met).

What have you tried so far?

1 Like