diff --git a/snippets/findLast.md b/snippets/findLast.md index 00263354a..911177269 100644 --- a/snippets/findLast.md +++ b/snippets/findLast.md @@ -2,10 +2,10 @@ 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]; +const findLast = (arr, fn) => arr.filter(fn).pop(); ``` ```js 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