Merge pull request #171 from iamsoorena/take-every-nth-element
take every nth element of an array
This commit is contained in:
8
snippets/take-every-nth-element.md
Normal file
8
snippets/take-every-nth-element.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
### Take every nth element of an array
|
||||||
|
|
||||||
|
Use `Array.filter()` to create a new array that contains every nth element of a given array.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const everynth = (arr, nth) => arr.filter((e, i) => i % nth === 0);
|
||||||
|
// everynth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ]
|
||||||
|
```
|
||||||
@ -86,6 +86,7 @@ swap-values-of-two-variables:utility
|
|||||||
tail-of-list:array
|
tail-of-list:array
|
||||||
take-right:array
|
take-right:array
|
||||||
take:array
|
take:array
|
||||||
|
take-every-nth-element:array
|
||||||
truncate-a-string:string
|
truncate-a-string:string
|
||||||
unique-values-of-array:array
|
unique-values-of-array:array
|
||||||
URL-parameters:utility
|
URL-parameters:utility
|
||||||
|
|||||||
Reference in New Issue
Block a user