source: node_modules/es-toolkit/dist/array/windowed.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 629 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function windowed(arr, size, step = 1, { partialWindows = false } = {}) {
6 if (size <= 0 || !Number.isInteger(size)) {
7 throw new Error('Size must be a positive integer.');
8 }
9 if (step <= 0 || !Number.isInteger(step)) {
10 throw new Error('Step must be a positive integer.');
11 }
12 const result = [];
13 const end = partialWindows ? arr.length : arr.length - size + 1;
14 for (let i = 0; i < end; i += step) {
15 result.push(arr.slice(i, i + size));
16 }
17 return result;
18}
19
20exports.windowed = windowed;
Note: See TracBrowser for help on using the repository browser.