Function: windows()
windows<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,count
:number
):IterableIterator
<ElementType
[]>
Creates an iterable with arrays of count
elements representing a sliding window.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | The iterator to take values from. |
count | number | The maximum number of values in the window. |
Returns
IterableIterator
<ElementType
[]>
An iterator that yields windows with count
values from the provided iterator.
Example
import { windows } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log([...windows(iterable, 2)]);
// Output: [[1, 2], [2, 3], [3, 4], [4, 5]]
Defined in
projects/utilities/packages/iterator-utilities/src/lib/windows.ts:22