Recursion datatypes question

My question is about the type of data of this line:
var counterArray = countdown(n-1)

I understand that this returns an array in the base case— but before that happens isn’t counterArray only an integer? The reason I’m confused is that before the base case, numbers are being unshift-ed to the variable like it is an array.

So can you just treat this line just like whatever type of data you put in the return statement of the base case and treat it like that type anytime during the recursion?

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

} countdown(10)
// 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/90.0.4430.212 Safari/537.36

Challenge: Use Recursion to Create a Countdown

Link to the challenge:

This function must always return an array for this to work. The base case returns an array, and the recursive case modifies the results from a ‘lower’ case, so this function does in fact always return an array.

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