Example 1 — Official Pairs, Triples, and Too-Big n
The three samples from the Ramda docs on the same five-item list.
const nums = [1, 2, 3, 4, 5];
console.log(R.aperture(2, nums)); // [[1, 2], [2, 3], [3, 4], [4, 5]]
console.log(R.aperture(3, nums)); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
console.log(R.aperture(7, nums)); // [] How It Works
- Pairs. A window of 2 starts at index 0 and moves one step at a time:
5 - 2 + 1 = 4windows. - Overlap. Each window shares one item with the next —
2is in both[1, 2]and[2, 3]. - Triples. A window of 3 fits
5 - 3 + 1 = 3times. - Too big. A window of 7 cannot fit in 5 items, so the result is
[].
