Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/lib/generators.ts>range

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function range
import { range } from "https://deno.land/x/iter@v3.2.3/lib/generators.ts";

Creates an iterable over an inclusive range of numbers.

Examples

Example 1

import * as iter from "https://deno.land/x/iter/mod.ts";

const range1 = iter.create.range(5);
console.log(...range1); // -> 0 1 2 3 4 5

const range2 = iter.create.range(11,16);
console.log(...range2); // -> 11 12 13 14 15 16

const range3 = iter.create.range(14,24,2);
console.log(...range3); // -> 14 16 18 20 22 24

const range4 = iter.create.range(12, 2, 2);
console.log(...range4); // -> 12 10 8 6 4 2

Parameters

endOrStart: number
  • If no other arguments are provided, the range will go from 0 until endOrRangeStart. Otherwise, this acts as the start of the range. To stress, this is inclusive, in contrast to Python's range() iterables.
optional
end: number
  • The end of the range.
optional
step = [UNSUPPORTED]
  • The amount to increment each time. Sign is ignored.

Returns

An iterable over the range.