From 70ec53e2f09d4dcb9effcfde2557fb6088c816c2 Mon Sep 17 00:00:00 2001 From: taltmann42 Date: Mon, 18 Dec 2017 19:12:51 +0100 Subject: [PATCH 1/4] Create drop-right.md --- snippets/drop-right.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 snippets/drop-right.md diff --git a/snippets/drop-right.md b/snippets/drop-right.md new file mode 100644 index 000000000..9c162327a --- /dev/null +++ b/snippets/drop-right.md @@ -0,0 +1,13 @@ +### Array dropRight + +Returns a new array with `n` elements removed from the right + +Checks if `n` is shorter than the given array and slices it accordingly or returns an empty array + +```js +const dropRight = (arr, n = 1) => (arr.length - n ) > 0 ? arr.slice(0, arr.length - n) : [] + +//dropRight([1,2,3]) -> [1,2] +//dropRight([1,2,3], 2) -> [1] +//dropRight([1,2,3], 42) -> [] +``` From ae7732cd3ed8d20a99a3fb48fb2108ffc8fe8442 Mon Sep 17 00:00:00 2001 From: taltmann42 Date: Mon, 18 Dec 2017 19:15:51 +0100 Subject: [PATCH 2/4] Update drop-right.md shorter comparison of `n` and `arr.length` --- snippets/drop-right.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/drop-right.md b/snippets/drop-right.md index 9c162327a..b1f7e02ed 100644 --- a/snippets/drop-right.md +++ b/snippets/drop-right.md @@ -5,7 +5,7 @@ Returns a new array with `n` elements removed from the right Checks if `n` is shorter than the given array and slices it accordingly or returns an empty array ```js -const dropRight = (arr, n = 1) => (arr.length - n ) > 0 ? arr.slice(0, arr.length - n) : [] +const (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - n) : [] //dropRight([1,2,3]) -> [1,2] //dropRight([1,2,3], 2) -> [1] From ba6d848ddc5b2a2fa5ec3471bc8a42d6e2df5212 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 12:06:47 +0200 Subject: [PATCH 3/4] Update and rename drop-right.md to dropRight.md --- snippets/drop-right.md | 13 ------------- snippets/dropRight.md | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 snippets/drop-right.md create mode 100644 snippets/dropRight.md diff --git a/snippets/drop-right.md b/snippets/drop-right.md deleted file mode 100644 index b1f7e02ed..000000000 --- a/snippets/drop-right.md +++ /dev/null @@ -1,13 +0,0 @@ -### Array dropRight - -Returns a new array with `n` elements removed from the right - -Checks if `n` is shorter than the given array and slices it accordingly or returns an empty array - -```js -const (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - n) : [] - -//dropRight([1,2,3]) -> [1,2] -//dropRight([1,2,3], 2) -> [1] -//dropRight([1,2,3], 42) -> [] -``` diff --git a/snippets/dropRight.md b/snippets/dropRight.md new file mode 100644 index 000000000..4d62721d0 --- /dev/null +++ b/snippets/dropRight.md @@ -0,0 +1,12 @@ +### Array dropRight + +Returns a new array with `n` elements removed from the right + +Check if `n` is shorter than the given array and use `Array.slice()` to slice it accordingly or return an empty array. + +```js +const dropRight = (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - n) : [] +//dropRight([1,2,3]) -> [1,2] +//dropRight([1,2,3], 2) -> [1] +//dropRight([1,2,3], 42) -> [] +``` From df1d659175421b40711257ec8515fe8ac3e39104 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 12:06:58 +0200 Subject: [PATCH 4/4] Update dropRight.md --- snippets/dropRight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/dropRight.md b/snippets/dropRight.md index 4d62721d0..d1a56d764 100644 --- a/snippets/dropRight.md +++ b/snippets/dropRight.md @@ -1,4 +1,4 @@ -### Array dropRight +### dropRight Returns a new array with `n` elements removed from the right