Fix findLast missing dependency (#4103)

This commit is contained in:
Luiz Américo
2018-12-05 22:10:43 -03:00
committed by John-David Dalton
parent c33df3147f
commit daf1f1b10b

View File

@@ -1,4 +1,3 @@
import createFind from './.internal/createFind.js'
import findLastIndex from './findLastIndex.js'
/**
@@ -17,6 +16,16 @@ import findLastIndex from './findLastIndex.js'
* findLast([1, 2, 3, 4], n => n % 2 == 1)
* // => 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