@dscottboggs/range
v1.0.0
Published
A simple range iterator implementation. Supports incrementing, decrementing, and infinite ranges.
Downloads
1
Readme
A simple range iterator implementation. Supports incrementing, decrementing, and infinite ranges.
Examples
- Simple range
for (let hour of range(24)) console.log(`${hour}:00`);
- Create a list
const hours = [...range(24)];
- Specify start and end
for (let hour of range(9, 17)) console.log("working");
- Infinite range (you can pass
Infinity
to the same effect)for (let value of range(10, null)) { const result = doSomethingWith(value); if (condition(result)) break; }
- Backwards range
for (let value of range(20, 10)) console.log("counting backwards: " + value);
- Backwards infinite range
for (let value of range(10, -Infinity)) { const result = doSomethingWith(value); if (condition(result)) break; }