/array/slidingWindow
stdReturns a new array composed of tuples of the given sliding window length of consecutive elements.
Type signature
(count: number) => <T>(xs: T[]) => T[][]
Examples
slidingWindow(2)([1, 2, 3, 4]);
// ⇒ [[1, 2], [2, 3], [3, 4]]
Try in REPL
slidingWindow(3)([1, 2, 3, 4, 5]);
// ⇒ [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
Try in REPL
slidingWindow(1)([
1, 2, 3, 4, 5, 6,
]);
// ⇒ [[1], [2], [3], [4], [5], [6]]
Try in REPL
Questions
- How to iterate an array pairwise?