mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Bump to v4.13.0.
This commit is contained in:
20
findLast.js
20
findLast.js
@@ -1,8 +1,6 @@
|
||||
var baseEachRight = require('./_baseEachRight'),
|
||||
baseFind = require('./_baseFind'),
|
||||
baseFindIndex = require('./_baseFindIndex'),
|
||||
baseIteratee = require('./_baseIteratee'),
|
||||
isArray = require('./isArray');
|
||||
var findLastIndex = require('./findLastIndex'),
|
||||
isArrayLike = require('./isArrayLike'),
|
||||
values = require('./values');
|
||||
|
||||
/**
|
||||
* This method is like `_.find` except that it iterates over elements of
|
||||
@@ -15,6 +13,7 @@ var baseEachRight = require('./_baseEachRight'),
|
||||
* @param {Array|Object} collection The collection to search.
|
||||
* @param {Array|Function|Object|string} [predicate=_.identity]
|
||||
* The function invoked per iteration.
|
||||
* @param {number} [fromIndex=collection.length-1] The index to search from.
|
||||
* @returns {*} Returns the matched element, else `undefined`.
|
||||
* @example
|
||||
*
|
||||
@@ -23,13 +22,10 @@ var baseEachRight = require('./_baseEachRight'),
|
||||
* });
|
||||
* // => 3
|
||||
*/
|
||||
function findLast(collection, predicate) {
|
||||
predicate = baseIteratee(predicate, 3);
|
||||
if (isArray(collection)) {
|
||||
var index = baseFindIndex(collection, predicate, true);
|
||||
return index > -1 ? collection[index] : undefined;
|
||||
}
|
||||
return baseFind(collection, predicate, baseEachRight);
|
||||
function findLast(collection, predicate, fromIndex) {
|
||||
collection = isArrayLike(collection) ? collection : values(collection);
|
||||
var index = findLastIndex(collection, predicate, fromIndex);
|
||||
return index > -1 ? collection[index] : undefined;
|
||||
}
|
||||
|
||||
module.exports = findLast;
|
||||
|
||||
Reference in New Issue
Block a user