update: map return in a simple way
This commit is contained in:
@ -12,11 +12,11 @@ If `n` is greater than the length of `arr`, return an empty array.
|
|||||||
const aperture = (n, arr) =>
|
const aperture = (n, arr) =>
|
||||||
n > arr.length
|
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
|
```js
|
||||||
R.aperture(2, [1, 2, 3, 4]); // [[1, 2], [2, 3], [3, 4]]
|
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]]
|
aperture(3, [1, 2, 3, 4]); // [[1, 2, 3], [2, 3, 4]]
|
||||||
R.aperture(5, [1, 2, 3, 4]); // []
|
aperture(5, [1, 2, 3, 4]); // []
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user