everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
21 lines (20 loc) • 533 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.slideWindow = void 0;
/**
* Sliding window with overlap.
* @author @dailker
* @template T
* @param {T[]} array
* @param {number} size
* @param {number} [step=1]
* @returns {T[][]}
*/
function slideWindow(array, size, step = 1) {
const result = [];
for (let i = 0; i + size <= array.length; i += step) {
result.push(array.slice(i, i + size));
}
return result;
}
exports.slideWindow = slideWindow;