💾range()

JSiterationiterableextension ⟩ 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

Was this helpful?