I was trying to solve a recursion problem that get the integers within a range (x, y).
This takes both negative and positive numbers.
An example of the expected results are:
range(2,9); // => [3,4,5,6,7,8]
range(7,2); // => [6, 5, 4, 3]
range(-9,-4)) // => [-8,-7,-6,-5]
Currently I have the ff:
var range = function(x, y) {
var result = [];
if(x < y){
for(var i = x+1; i < y; i++){
result.push(i);
}
return result;
}
if(x > y){
for(var j = x-1; j > y; j--){
result.push(j);
}
return result;
}
};
How can I convert my for loops into recursion with the given rules.