Подмассивы последовательных элементов
const aperture = (n, arr) => n > arr.length ? [] : arr.slice(n - 1).map((v, i) => arr.slice(i, i + n));
const findConsecutive = (arr, n) => arr.slice(n - 1).map((v, i) => arr.slice(i, i + n));
aperture(2, [1, 2, 3, 4]); // [[1, 2], [2, 3], [3, 4]] aperture(3, [1, 2, 3, 4]); // [[1, 2, 3], [2, 3, 4]] aperture(5, [1, 2, 3, 4]); // []
findConsecutive([1, 2, 3, 4, 5], 2); // [[1, 2], [2, 3], [3, 4], [4, 5]]