Merge pull request #60 from benhanks040888/master

Check for array length in tail function to return the correct value f…
This commit is contained in:
Angelos Chalaris
2017-12-13 11:39:30 +02:00
committed by GitHub
2 changed files with 4 additions and 2 deletions

View File

@ -515,8 +515,9 @@ Use array destructuring to swap values between two variables.
Return `arr.slice(1)`. Return `arr.slice(1)`.
```js ```js
const tail = arr => arr.slice(1); const tail = arr => arr.length > 1 ? arr.slice(1) : arr;
// tail([1,2,3]) -> [2,3] // tail([1,2,3]) -> [2,3]
// tail([1]) -> [1]
``` ```
### Unique values of array ### Unique values of array

View File

@ -3,6 +3,7 @@
Return `arr.slice(1)`. Return `arr.slice(1)`.
```js ```js
const tail = arr => arr.slice(1); const tail = arr => arr.length > 1 ? arr.slice(1) : arr;
// tail([1,2,3]) -> [2,3] // tail([1,2,3]) -> [2,3]
// tail([1]) -> [1]
``` ```