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

    Function intersperse

    • Inserts the specified separator between adjoining elements.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TSeparator

        Type of separator to insert.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • separator: TSeparator

        Value inserted between consecutive elements.

      Returns IEnumerable<TElement | TSeparator>

      A sequence containing the original elements with separators interleaved.

      No separator precedes the first element or follows the last element.

      const letters = ['a', 'b', 'c'];
      const interspersed = intersperse(letters, '-').toArray();
      console.log(interspersed); // ['a', '-', 'b', '-', 'c']