Merge pull request #1196 from yinsang/feature/aperture

update: map return in a simple way
This commit is contained in:
Angelos Chalaris
2020-09-02 12:42:20 +03:00
committed by GitHub

View File

@ -12,11 +12,11 @@ If `n` is greater than the length of `arr`, return an empty array.
const aperture = (n, arr) =>
n > arr.length
? []
: arr.slice(n - 1).map((v, i) => [...arr.slice(i, i + n - 1), v]);
: arr.slice(n - 1).map((v, i) => arr.slice(i, i + n));
```
```js
R.aperture(2, [1, 2, 3, 4]); // [[1, 2], [2, 3], [3, 4]]
R.aperture(3, [1, 2, 3, 4]); // [[1, 2, 3], [2, 3, 4]]
R.aperture(5, [1, 2, 3, 4]); // []
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]); // []
```