-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathfindLast.js
27 lines (25 loc) · 1.02 KB
/
findLast.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
define(['../internal/baseCallback', '../internal/baseEachRight', '../internal/baseFind'], function(baseCallback, baseEachRight, baseFind) {
/**
* This method is like `_.find` except that it iterates over elements of
* `collection` from right to left.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
* _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
* // => 3
*/
function findLast(collection, predicate, thisArg) {
predicate = baseCallback(predicate, thisArg, 3);
return baseFind(collection, predicate, baseEachRight);
}
return findLast;
});