windowed es-toolkit
Returns a new array containing snapshots of each window as a window of specified size slides regularly along the array.
Usage
windowed(arr, size, step?, options?)
Use windowed when you want to return an array containing snapshots as a window of specified size slides regularly along an array.
It's useful for calculating moving averages in time series data analysis, extracting n-grams from strings, or finding specific patterns in arrays. It can also be used for processing data in batch units or implementing sliding window algorithms.
Use the partialWindows option if you want to include partial windows.
Each snapshot is provided in array form, and the last few arrays may have fewer elements than the specified size.
Parameters
The array to create windows from.
The size of each window. Must be a positive integer.
The spacing between windows. Must be a positive integer. Default is 1.
Whether to include incomplete windows at the end of the array. Default is false.
Returns
An array of windows created with the specified size and spacing.
Throws
Throws an error if size or step is not a positive integer.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.