const arr = Array.from({ length: max - min + 1 }, (n, i) => i + min);
или
function* range(start, stop, step) {
if (stop === undefined) {
stop = start;
start = 0;
}
if (start === stop) {
step = 1;
}
if (step === undefined) {
step = Math.sign(stop - start);
}
if (start <= stop && step > 0 || start >= stop && step < 0) {
for (let i = start; step < 0 ? i >= stop : i <= stop; i += step) {
yield i;
}
}
}
console.log(Array.from(range(3, 9))); // [3, 4, 5, 6, 7, 8, 9]
console.log([...range(-5)]); // [0, -1, -2, -3, -4, -5]
for (const n of range(100, 200, 33)) {
console.log(n); // 100 133 166 199
}
const r = range(12, -7, -5);
for (let n; !(n = r.next()).done; ) {
console.log(n.value); // 12 7 2 -3
}