// Created on savesnippets.com ยท https://savesnippets.com/X4wydtn6eqV6P6 function range(start, end, step = 1) { const result = []; if (step === 0) throw new Error('step cannot be 0'); for (let i = start; step > 0 ? i <= end : i >= end; i += step) { result.push(i); } return result; } // Usage console.log(range(1, 5)); // [1, 2, 3, 4, 5] console.log(range(0, 10, 2)); // [0, 2, 4, 6, 8, 10] console.log(range(5, 1, -1)); // [5, 4, 3, 2, 1]