const range = (options) => {
const { from = 0, step = 1, to } = options;
if (to <= from) {
throw Error(`"Error: from (${from}) >= to (${to})"`);
}
return Array.from(
{ length: Math.ceil((to - from) / step) },
(_, i) => i * step + from
);
};
let rng = range({ from: 1, to: 10 });
console.log(rng);
/*
run:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
*/