From daf1f1b10b0b40032ec053891eea12863a1540d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Wed, 5 Dec 2018 22:10:43 -0300 Subject: [PATCH] Fix findLast missing dependency (#4103) --- findLast.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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