diff --git a/README.md b/README.md index 3abae27c6..4a1ea0529 100644 --- a/README.md +++ b/README.md @@ -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) -> [] diff --git a/snippets/take.md b/snippets/take.md index 1cc7e77fe..f597728ea 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -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) -> []