From c816ce85ce88ab10b1a7833dd712b81557d6d20d Mon Sep 17 00:00:00 2001 From: David Narbutovich Date: Sat, 23 Dec 2017 14:00:04 +0300 Subject: [PATCH 1/2] =?UTF-8?q?Bad=20example=F0=9F=91=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The slice function can take the negative negative value of the second agrimement --- snippets/dropRight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/dropRight.md b/snippets/dropRight.md index d1a56d764..985df7ac3 100644 --- a/snippets/dropRight.md +++ b/snippets/dropRight.md @@ -5,7 +5,7 @@ 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) : [] +const dropRight = (arr, n = 1) => arr.slice(0, -n) //dropRight([1,2,3]) -> [1,2] //dropRight([1,2,3], 2) -> [1] //dropRight([1,2,3], 42) -> [] From b1adedfbeab432e2efbbf357a4495c1102654583 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 24 Dec 2017 14:11:30 +0200 Subject: [PATCH 2/2] Update dropRight.md --- snippets/dropRight.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/dropRight.md b/snippets/dropRight.md index 985df7ac3..a39613a14 100644 --- a/snippets/dropRight.md +++ b/snippets/dropRight.md @@ -1,11 +1,11 @@ ### dropRight -Returns a new array with `n` elements removed from the right +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. +Use `Array.slice()` to slice the remove the specified number of elements from the right. ```js -const dropRight = (arr, n = 1) => arr.slice(0, -n) +const dropRight = (arr, n = 1) => arr.slice(0, -n); //dropRight([1,2,3]) -> [1,2] //dropRight([1,2,3], 2) -> [1] //dropRight([1,2,3], 42) -> []