From 06c616b75cb22b8adf6f923d61225608f48247af Mon Sep 17 00:00:00 2001 From: Siarhei Date: Fri, 11 May 2018 16:05:36 +0400 Subject: [PATCH 1/3] Simplify findLast snippet --- test/findLast/findLast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/findLast/findLast.js b/test/findLast/findLast.js index 82f3a11e6..38f769e78 100644 --- a/test/findLast/findLast.js +++ b/test/findLast/findLast.js @@ -1,2 +1,2 @@ -const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0]; +const findLast = (arr, fn) => arr.filter(fn).pop(); module.exports = findLast; \ No newline at end of file From 656b0492d63ab878a5d0376c36efbf1f956c4c9e Mon Sep 17 00:00:00 2001 From: Siarhei Date: Fri, 11 May 2018 16:10:15 +0400 Subject: [PATCH 2/3] Fix findLast snippet docs --- snippets/findLast.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/findLast.md b/snippets/findLast.md index 00263354a..1a3ae39b6 100644 --- a/snippets/findLast.md +++ b/snippets/findLast.md @@ -2,7 +2,7 @@ Returns the last element for which the provided function returns a truthy value. -Use `Array.filter()` to remove elements for which `fn` returns falsey values, `Array.slice(-1)` to get the last one. +Use `Array.filter()` to remove elements for which `fn` returns falsey values, `Array.pop()` to get the last one. ```js const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0]; From 2e122516cdfea6da7bcf3de88df6490899750ded Mon Sep 17 00:00:00 2001 From: Siarhei Date: Fri, 11 May 2018 16:18:35 +0400 Subject: [PATCH 3/3] Fix findLast docs code --- snippets/findLast.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/findLast.md b/snippets/findLast.md index 1a3ae39b6..911177269 100644 --- a/snippets/findLast.md +++ b/snippets/findLast.md @@ -5,7 +5,7 @@ Returns the last element for which the provided function returns a truthy value. Use `Array.filter()` to remove elements for which `fn` returns falsey values, `Array.pop()` to get the last one. ```js -const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0]; +const findLast = (arr, fn) => arr.filter(fn).pop(); ``` ```js