ESify find implementation.

This commit is contained in:
Michał Lipiński
2017-04-03 11:53:13 +02:00
parent 6dc03831d8
commit 53cac4eef4

10
find.js
View File

@@ -26,13 +26,13 @@ import keys from './keys'
* // => object for 'barney' * // => object for 'barney'
*/ */
function find(collection, predicate, fromIndex) { function find(collection, predicate, fromIndex) {
var iterable = Object(collection); const iterable = Object(collection)
if (!isArrayLike(collection)) { if (!isArrayLike(collection)) {
collection = keys(collection); collection = keys(collection)
predicate = function(key) { return iteratee(iterable[key], key, iterable); }; predicate = (key) => iteratee(iterable[key], key, iterable)
} }
var index = findIndex(collection, predicate, fromIndex); const index = findIndex(collection, predicate, fromIndex)
return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined
} }
export default find export default find