• Creates the list of numbers from start to end with stepping, adding by step.

    Parameters

    • start: number

      The start of the range (inclusive).

    • end: number

      The end of the range (exclusive).

    • step: number = 1

      The steps of the numbers. Defaults to 1. Setting step to 0 will make the list infinite.

    Returns List<number>

    The list of numbers in the range.

    Examples

    import { range, toArray } from "./list.ts";
    import { assertEquals } from "../deps.ts";

    assertEquals(toArray(range(0, 5)), [0, 1, 2, 3, 4]);
    assertEquals(toArray(range(0, 5, 0.5)), [
    0,
    0.5,
    1,
    1.5,
    2,
    2.5,
    3,
    3.5,
    4,
    4.5,
    ]);
    assertEquals(toArray(range(2, 3)), [2]);
    assertEquals(toArray(range(3, 6)), [3, 4, 5]);
    assertEquals(toArray(range(3, 3)), []);
    assertEquals(toArray(range(5, 0)), []);
    assertEquals(toArray(range(3, 2)), []);

Generated using TypeDoc