Get the integers within a range (x, y) using recursion
chandra penugonda
Posted on February 14, 2022
Problem Statement
Get the integers within a range (x, y)
input: (2,9)
output: [3,4,5,6,7,8]
var range = function(x, y) {
// start here
};
Solution
var range = function (x, y) {
if (y === x + 1) return [x];
return [x].concat(range(x + 1, y));
};
💖 💪 🙅 🚩
chandra penugonda
Posted on February 14, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.