I might be slightly confused here because what you posted works. Did you code this yourself or did you copy a working solution and just want it explained?
As far as explaining, I don’t think you need a line by line explanation, do you? I’m guessing you understand what the following block of code does:
if (endNum - startNum === 0) {
return [startNum];
}
So in order to keep us from having to guess and type out unnecessary information, please be a little more specific and let us know exactly what you do not understand.
I applied basic recursive rule here but one thing got me stuck.
Just this else step,
i don’t get it by comparing with values,
If i pass any value, lets say ((1, 5)… -
const newNum = rangeOfNumbers(1, 5 - 1); //which is (1, 4)
newNum.push(5); // which should be like (1, 4, 5) if i’m not wrong.
newNum will hold an array. That array will be the return value of rangeOfNumbers(1, 4). So what will rangeOfNumbers(1, 4) return? Well, you have to start the whole process over again because it’s a new recursive function call.