From 1bdda20e497b989d8c33b5fd67276516646e0b45 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 31 Mar 2017 21:36:56 -0700 Subject: [PATCH] Reimplement find. --- find.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/find.js b/find.js index 199e29aa7..2f3df8356 100644 --- a/find.js +++ b/find.js @@ -1,5 +1,6 @@ -import createFind from './.internal/createFind.js' import findIndex from './findIndex.js' +import isArrayLike from './isArrayLike' +import keys from './keys' /** * Iterates over elements of `collection`, returning the first element @@ -24,6 +25,14 @@ import findIndex from './findIndex.js' * find(users, ({ age }) => age < 40) * // => object for 'barney' */ -const find = createFind(findIndex) +function find(collection, predicate, fromIndex) { + var iterable = Object(collection); + if (!isArrayLike(collection)) { + collection = keys(collection); + predicate = function(key) { return iteratee(iterable[key], key, iterable); }; + } + var index = findIndex(collection, predicate, fromIndex); + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; +} export default find