mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Fix findLast missing dependency (#4103)
This commit is contained in:
committed by
John-David Dalton
parent
c33df3147f
commit
daf1f1b10b
13
findLast.js
13
findLast.js
@@ -1,4 +1,3 @@
|
|||||||
import createFind from './.internal/createFind.js'
|
|
||||||
import findLastIndex from './findLastIndex.js'
|
import findLastIndex from './findLastIndex.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,6 +16,16 @@ import findLastIndex from './findLastIndex.js'
|
|||||||
* findLast([1, 2, 3, 4], n => n % 2 == 1)
|
* findLast([1, 2, 3, 4], n => n % 2 == 1)
|
||||||
* // => 3
|
* // => 3
|
||||||
*/
|
*/
|
||||||
const findLast = createFind(findLastIndex)
|
function findLast (collection, predicate, fromIndex) {
|
||||||
|
let iteratee
|
||||||
|
const iterable = Object(collection)
|
||||||
|
if (!isArrayLike(collection)) {
|
||||||
|
collection = Object.keys(collection)
|
||||||
|
iteratee = predicate
|
||||||
|
predicate = key => iteratee(iterable[key], key, iterable)
|
||||||
|
}
|
||||||
|
const index = findLastIndex(collection, predicate, fromIndex)
|
||||||
|
return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export default findLast
|
export default findLast
|
||||||
|
|||||||
Reference in New Issue
Block a user