Update take-every-nth-element.md
This commit is contained in:
@ -3,8 +3,6 @@
|
|||||||
Use `Array.filter()` to create a new array that contains every nth element of a given array.
|
Use `Array.filter()` to create a new array that contains every nth element of a given array.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const everynth = (arr, nth) => arr.filter((e, i) => i % nth === 0)
|
const everynth = (arr, nth) => arr.filter((e, i) => i % nth === 0);
|
||||||
/*
|
// everynth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ]
|
||||||
console.log(everynth([1,2,3,4,5,6], 2)) // -> [ 1, 3, 5 ]
|
|
||||||
*/
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user