From 8ca776aa03843deca3dfc5c6fd18f89259762b2f Mon Sep 17 00:00:00 2001 From: King Date: Thu, 14 Dec 2017 04:35:14 -0500 Subject: [PATCH 1/4] ran npm run build-list & add take.md --- README.md | 14 +++++++++++++- snippets/take.md | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 snippets/take.md diff --git a/README.md b/README.md index d0393e21a..3abae27c6 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ * [Promisify](#promisify) * [Random integer in range](#random-integer-in-range) * [Random number in range](#random-number-in-range) -* [Redirect to URL](#redirect-to-url) +* [Redirect to url](#redirect-to-url) * [Reverse a string](#reverse-a-string) * [RGB to hexadecimal](#rgb-to-hexadecimal) * [Run promises in series](#run-promises-in-series) @@ -70,6 +70,7 @@ * [Sum of array of numbers](#sum-of-array-of-numbers) * [Swap values of two variables](#swap-values-of-two-variables) * [Tail of list](#tail-of-list) +* [Take](#take) * [Truncate a string](#truncate-a-string) * [Unique values of array](#unique-values-of-array) * [URL parameters](#url-parameters) @@ -743,6 +744,17 @@ const tail = arr => arr.length > 1 ? arr.slice(1) : arr; // tail([1]) -> [1] ``` +### Take + +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); + +// take([1, 2, 3], 5) -> [1, 2, 3] +// take([1, 2, 3], 0) -> [] +``` + ### Truncate a String Determine if the string's `length` is greater than `num`. diff --git a/snippets/take.md b/snippets/take.md new file mode 100644 index 000000000..1cc7e77fe --- /dev/null +++ b/snippets/take.md @@ -0,0 +1,10 @@ +### Take + +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); + +// take([1, 2, 3], 5) -> [1, 2, 3] +// take([1, 2, 3], 0) -> [] +``` From 236616efea4cbc88a0bde56b186addc4d19ce78b Mon Sep 17 00:00:00 2001 From: King Date: Thu, 14 Dec 2017 04:46:16 -0500 Subject: [PATCH 2/4] refactor take --- README.md | 2 +- snippets/take.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) -> [] From db28e1ee28385d8946e09ebdcf6f30da1b0b7507 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 11:50:52 +0200 Subject: [PATCH 3/4] Update take.md --- snippets/take.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/take.md b/snippets/take.md index f597728ea..80142031d 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -1,6 +1,6 @@ ### Take -Use `.slice()` to create a slice of the array with n elements taken from the beginning. +Use `Array.slice()` to create a slice of the array with `n` elements taken from the beginning. ```js const take = (arr, n = 1) => arr.slice(0, n); From a93268e5969c77c38d9a587056581cb39f2b0835 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 11:51:24 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a1ea0529..0c9b72501 100644 --- a/README.md +++ b/README.md @@ -746,7 +746,7 @@ const tail = arr => arr.length > 1 ? arr.slice(1) : arr; ### Take -Use `.slice()` to create a slice of the array with n elements taken from the beginning. +Use `Array.slice()` to create a slice of the array with `n` elements taken from the beginning. ```js const take = (arr, n = 1) => arr.slice(0, n);