By the way, I stole these problems from : http://www.w3resource.com/javascript-exercises/javascript-recursion-functions-exercises.php
Write a recursive function to get integers in a range.
For example, range(2,7) will return [3,4,5,6];
Yes, that is returned in an array.
Answer is in the comments.
var range = function(start_num, end_num)
ReplyDelete{
if (end_num - start_num === 2)
{
return [start_num + 1];
}
else
{
var list = range(start_num, end_num - 1);
list.push(end_num - 1);
return list;
}
};