An immutable sequence of numbers. It implements both Iterable and
AsyncIterable.
It is similar to Python's range() function.
The length of the range. Note that it guarantees to return the same value
as Array.from(range).length.
import { range } from "./range.ts"; console.log(range(10, -10, -3.5).length);
The above example will print 6.
Iterates over the elements of the range, in an asynchronous manner.
import { range } from "./range.ts"; for await (const value of range(4)) console.log(value);
The above example will print the following 4 lines:
0 1 2 3
Iterates over the elements of the range.
import { range } from "./range.ts"; for (const value of range(4n)) console.log(value);
The above example will print the following 4 lines:
0 1 2 3
Returns the element at the specified index in the range. Note that it
guarantees to return the same value as Array.from(range).at(index).
import { range } from "./range.ts"; const r = range(10, -10, -3.5); console.log(r.at(3), r.at(-1));
The above example will print the following 2 lines:
-0.5 -7.5