update: map return in a simple way

This commit is contained in:
魏银鹏
2020-09-02 17:35:13 +08:00
parent a0290983b3
commit 0834aee18f

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]); // []
```