mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Bump to v4.13.0.
This commit is contained in:
14
findLast.js
14
findLast.js
@@ -1,4 +1,4 @@
|
||||
define(['./_baseEachRight', './_baseFind', './_baseFindIndex', './_baseIteratee', './isArray'], function(baseEachRight, baseFind, baseFindIndex, baseIteratee, isArray) {
|
||||
define(['./findLastIndex', './isArrayLike', './values'], function(findLastIndex, isArrayLike, values) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
@@ -14,6 +14,7 @@ define(['./_baseEachRight', './_baseFind', './_baseFindIndex', './_baseIteratee'
|
||||
* @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
|
||||
*
|
||||
@@ -22,13 +23,10 @@ define(['./_baseEachRight', './_baseFind', './_baseFindIndex', './_baseIteratee'
|
||||
* });
|
||||
* // => 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;
|
||||
}
|
||||
|
||||
return findLast;
|
||||
|
||||
Reference in New Issue
Block a user