function range(start, end) { if(start === end) return [start]; return [start, ...range(start + 1, end)]; } range(1, 4) //Output: Array(4) [ 1, 2, 3, 4 ]