range
Create a range used for iterating
Usage
Given a start, end, value, and step size returns a generator that will yield values from start to end by step size. Useful for replacing for (let i = 0)
with for of
. Range will return a generator that for of
will call one at a time, so it’s safe to create large ranges.
The interface is identical to list
.
A hat tip to Python’s range
functionality
Signatures
The range function can do a lot with different arguments.
range(size)
When givin a single argument, it’s treated as the size
. Returns a generator that yields values from 0 to size
.
range(start, end)
When given two arguments, they’re treated as the start
and end
. Returns a generator that yields values from start
to end
range(start, end, value)
When given a third argument it’s treated as the value
to be yielded in the generator. If the value
is a function it will be called, with an index argument, to create every value.
range(start, end, value, step)
When given a fourth argument it’s treated as the step
size to skip when yielding values from start
to end
.