@webreflection/range
v0.1.1
Published
A Pythonic `range(...)` utility that works with both `for/of` and `in` operations
Downloads
2
Readme
@webreflection/range
A Pythonic range(start[, stop[, steps = 1]])
function that works in both for / of
and with value in range(...)
operations.
import range from '@webreflection/range';
for (const i of range(0, 3))
console.log(i); // 0, 1, 2
if (1 in range(0, 2))
console.log('1 is in range [0, 1, 2]');
API
range(3)
is equivalent ofrange(0, 3)
and yields[0, 1, 2]
range(3, 5)
will yield[3, 4]
range(0, 5, 2)
will yield[0, 2, 4]
;1 in range(0, 2)
will betrue
but2 in range(0, 2)
will be false[...range(0, 3)]
is valid asfor (const i of range(0, 3));
That's it.