Skip to content

spreadEvenly

spreadEvenly<T>(special, rest): IterableIterator<T>

Defined in: distribute/spread-evenly.ts:18

Interleaves special items into rest at evenly-spaced positions.

Each special item is placed at the center of an equal-length slot so that special items are spread as uniformly as possible through the combined sequence — the same reasoning as Bresenham’s line algorithm, distributing k items across n positions without accumulating drift.

Time complexity: O(n) in the combined length. Both inputs are read in full before the first item is yielded, since the spacing depends on both counts.

T

readonly T[]

Items to distribute evenly.

readonly T[]

Items to fill the gaps.

IterableIterator<T>

An iterator over the combined sequence.