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

    Function interleave

    • Interleaves the sequence with another iterable, yielding elements in alternating order.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TSecond

        Type of elements in the second iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • other: Iterable<TSecond>

        Iterable whose elements are alternated with the current sequence.

      Returns IEnumerable<TElement | TSecond>

      A sequence that alternates between elements from source and other.

      If one sequence is longer, the remaining elements are appended after the shorter sequence is exhausted. Enumeration is deferred.

      const numbers1 = [1, 3, 5];
      const numbers2 = [2, 4, 6];
      const interleaved = interleave(numbers1, numbers2).toArray();
      console.log(interleaved); // [1, 2, 3, 4, 5, 6]