diff --git a/findLast.js b/findLast.js index afd03ef9d..3f33f09a0 100644 --- a/findLast.js +++ b/findLast.js @@ -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