Skip to content

Commit

Permalink
update: map return in a simple way
Browse files Browse the repository at this point in the history
  • Loading branch information
魏银鹏 authored and 魏银鹏 committed Sep 2, 2020
1 parent a029098 commit 0834aee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snippets/aperture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]); // []
```

0 comments on commit 0834aee

Please sign in to comment.