Link Search Menu Expand Document

Use Recursion to Create a Countdown

Summary

  • The base case tells the recursive function when it no longer needs to call itself.
  • The recursive call executres the original function with different arguments.

Final Code

// Only change code below this line
function countdown(n) {
  if (n < 1) {
    return [];
  } else {
    const arr = countdown(n - 1);
    arr.unshift(n);
    return arr;
  }
}
// Only change code above this line