@mirei/ts-collections
    Preparing search index...

    Function sequence

    • Generates a numeric sequence from the specified start value to the end value (inclusive) with the given step.

      Parameters

      • start: number

        Start value of the sequence.

      • end: number

        End value of the sequence (inclusive).

      • step: number

        Step size between consecutive values. Must be positive when ascending, negative when descending, and zero only when start equals end.

      Returns IEnumerable<number>

      A sequence of numbers from start to end (inclusive) incremented by step.

      Thrown when any parameter is NaN, when step direction doesn't match the start/end relationship, or when step is zero and start doesn't equal end.

      Enumeration is deferred. The sequence includes end if it is reachable from start using the given step. For ascending sequences (start < end), step must be positive. For descending sequences (start > end), step must be negative.

      const ascending = sequence(1, 10, 1).toArray();
      console.log(ascending); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      const descending = sequence(10, 1, -1).toArray();
      console.log(descending); // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
      const stepped = sequence(1, 10, 2).toArray();
      console.log(stepped); // [1, 3, 5, 7, 9]