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

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

Added visualizations

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