windowed
windowed<
T>(iterable,size,step?):IterableIterator<T[]>
Defined in: packages/core/src/iterable/windowed.ts:22
Yields every overlapping window of size consecutive elements.
Not chunk: windows overlap, chunks do not. windowed([1, 2, 3], 2) yields
[1, 2] then [2, 3], where chunk([1, 2, 3], 2) yields [1, 2] then
[3]. Passing step equal to size makes the two agree, except that a
short trailing group is never yielded here.
An input shorter than size yields nothing, and so does the tail left over
when the length is not reached again — a window is only ever yielded at full
width.
Time complexity: O(n), allocating one array per window.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
number
How many elements per window. Must be a positive integer.
number = 1
How far to advance between windows. Must be a positive integer; a
value above size skips elements entirely.
Returns
Section titled “Returns”IterableIterator<T[]>
An iterator over the windows.
Throws
Section titled “Throws”If size or step is not a positive integer.