update snippets 78 - 96
This commit is contained in:
@ -8,6 +8,9 @@ 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'
|
||||
```
|
||||
|
||||
```js
|
||||
nthElement(['a','b','c'],1) -> 'b'
|
||||
nthElement(['a','b','b'],-3) -> 'a'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user