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

    Function step

    • Returns every n-th element of the sequence, starting with the first.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • step: number

        Positive interval indicating how many elements to skip between yielded items.

      Returns IEnumerable<TElement>

      A deferred sequence containing elements whose zero-based index is divisible by step.

      Thrown when step is less than 1.

      source is enumerated exactly once; elements that are not yielded are still visited to honour the stepping interval.

      const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
      const stepped = step(numbers, 3).toArray();
      console.log(stepped); // [1, 4, 7]