Function range

  • Generates a sequence of numbers within a specified range.

    Returns

    A generator yielding the next number in the sequence.

    Throws

    If the start, end, or step arguments are not finite numbers.

    Example

    for(const i of range(3)) console.log(i);
    // 0, 1, 2

    Example

    for(const i of range(3, 5)) console.log(i);
    // 3, 4

    Example

    for(const i of range(3, 8, 2)) console.log(i);
    // 3, 5, 7

    Example

    for(const i of range(3, -8, 2)) console.log(i);
    // 3, 1, -1, -3, -5, -7

    Parameters

    • start: number

      The inclusive start of the range.

    • Optional end: number

      The exclusive end of the range. If it is not provided, then start is used as the exclusive end, and the sequence will start from 0.

    • step: number = 1

      The step to increment the sequence by. If not provided, it defaults to 1.

    Returns Generator<number, void, unknown>

Generated using TypeDoc