Add findLast

This commit is contained in:
Angelos Chalaris
2018-01-11 13:51:58 +02:00
parent 1ea24c068d
commit a7506d6d0e
2 changed files with 14 additions and 0 deletions

13
snippets/findLast.md Normal file
View File

@ -0,0 +1,13 @@
### findLast
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.
```js
const findLast = (arr, fn) => arr.filter(fn).slice(-1);
```
```js
findLast([1, 2, 3, 4], n => n % 2 === 1) // 3
```

View File

@ -44,6 +44,7 @@ extendHex:utility,string
factorial:math,recursion factorial:math,recursion
fibonacci:math,array fibonacci:math,array
filterNonUnique:array filterNonUnique:array
findLast:array
flatten:array flatten:array
flip:adapter,function flip:adapter,function
forEachRight:array,function forEachRight:array,function