update snippets 78 - 96

This commit is contained in:
Stefan Feješ
2017-12-25 14:33:49 +01:00
committed by Agamemnon Zorbas
parent c829ed692e
commit 9ef34b7392
18 changed files with 90 additions and 43 deletions

View File

@ -7,7 +7,10 @@ If the index is out of bounds, return `[]`.
Omit the second argument, `n`, to get the first element of the array.
```js
const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
// nthElement(['a','b','c'],1) -> 'b'
// nthElement(['a','b','b'],-3) -> 'a'
const nthElement = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0];
```
```js
nthElement(['a','b','c'],1) // 'b'
nthElement(['a','b','b'],-3) // 'a'
```