How the table is create


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

I don’t understand how countArray was become a table.
My question is simple, how the table is create ?

Remember that recursive function first needs to reach the base case, to finish operations started on each step.

As base case here returns empty array, it is assigned to the countArray when n = 2

countArray = countdown(2 - 1) => []

This allows to step-by-step finish operations for larger n. Try to follow by hand this order.

ok thank you sanity.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.