💾range()

JSiterationiterableextension ⟩ range()

(iterable) half-open range of numbers.

range(0, 5),        // 0, 1, 2, 3, 4
range(0, 10, 2),    // 0, 2, 4, 6, 8
range(1, 2, 0.3),   // 1, 1.3, 1.6, 1.9000000000000001
range(2, -3),       // (empty iterable)

💾 replit ⟩ range()

// ⭐️ half-open range: [start, end)
function range(start, end, step = 1) {
    // return an iterable
    return {
        *[Symbol.iterator]() {
            for (let i = start; start <= i && i < end; i += step) {
                yield i;
            }
        }
    }
}

Last updated