ELIM Recursion and setting recursive variables

So I am already passed the recursion tutorials in the curriculum but I can’t seem to figure it out without googling for help. I understand the very basics but some things trip me up and I can’t wrap my head around yet.
Like in the challenge where you use recursion to make an array: Why do they set a variable as the function?
let arr = makeRangeOfNumbers(startNum, endNum - 1);
I can’t figure out how giving a variable a recursive function is able to push numbers into it when arr isn’t an array yet? I was setting arr as [ ] first but that got me nowhere.

Anyways I’m lost.

The makeRangeOfNumbers function returns an array. The arr value is assigned the return value of makeRangeOfNumbers(startNum, endNum - 1), which is an array.

Imagine a simpler example.

function rangeFromOneToTen() {
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

let arr = rangeFromOneToTen();

console.log(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Wow that really clears it up for me thanks!

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