function rangeOfNumbers(startNum, endNum) {
if(endNum - startNum === 0){
return[startNum];
}else{
var num = rangeOfNumbers(startNum, endNum - 1);
num.push(endNum);
return num;
}
};
console.log(rangeOfNumbers(1, 6))
How does the program know var num = rangeOfNumbers(startNum, endNum - 1); num should be a list and startNum is the first item and endNum the last item of it.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36.
Challenge: Use Recursion to Create a Range of Numbers
I am not sure exactly what you are asking, because the program does not know…you tell it.
// Define the function
function rangeOfNumbers(startNum, endNum) {
//// Do stuff
}
// Call the function, telling it 'startNum === 1', 'endNum === 6'
rangeOfNumbers(1, 6)