Check for array length in tail function to return the correct value for single-value arrays.

This commit is contained in:
Hendra Susanto
2017-12-13 16:37:41 +07:00
parent 0a114151c0
commit f53f1e4a52
2 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,7 @@
Return `arr.slice(1)`.
```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]) -> [1]
```