Merge pull request #664 from Siarhei-Zharnasek/master

Simplify findLast snippet
This commit is contained in:
Robert Mennell
2018-05-11 08:08:24 -07:00
committed by GitHub
2 changed files with 3 additions and 3 deletions

View File

@ -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

View File

@ -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;