Skip to content

Function.sliding

github-actions[bot] edited this page Sep 1, 2026 · 27 revisions

umt / sliding

Function: sliding()

sliding<T>(array, size, step?): T[][]

Defined in: Array/sliding.ts:10

Returns overlapping windows of a fixed size from an array

Type Parameters

T

T

Parameters

array

T[]

The array to window

size

number

Window size

step?

number = 1

Step between window starts

Returns

T[][]

Array of windows (incomplete trailing windows are omitted)

Examples

sliding([1, 2, 3, 4, 5], 3); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
sliding([1, 2, 3, 4, 5], 3, 2); // [[1, 2, 3], [3, 4, 5]]

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally