refactor take

This commit is contained in:
King
2017-12-14 04:46:16 -05:00
parent 8ca776aa03
commit 236616efea
2 changed files with 2 additions and 2 deletions

View File

@ -749,7 +749,7 @@ const tail = arr => arr.length > 1 ? arr.slice(1) : arr;
Use `.slice()` to create a slice of the array with n elements taken from the beginning.
```js
const take = (arr, n) => n === undefined ? arr.slice(0, 1) : arr.slice(0, n);
const take = (arr, n = 1) => arr.slice(0, n);
// take([1, 2, 3], 5) -> [1, 2, 3]
// take([1, 2, 3], 0) -> []

View File

@ -3,7 +3,7 @@
Use `.slice()` to create a slice of the array with n elements taken from the beginning.
```js
const take = (arr, n) => n === undefined ? arr.slice(0, 1) : arr.slice(0, n);
const take = (arr, n = 1) => arr.slice(0, n);
// take([1, 2, 3], 5) -> [1, 2, 3]
// take([1, 2, 3], 0) -> []