Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / findLast.js
1 var baseEachRight = require('./internal/baseEachRight'),
2     baseFind = require('./internal/baseFind'),
3     baseFindIndex = require('./internal/baseFindIndex'),
4     baseIteratee = require('./internal/baseIteratee'),
5     isArray = require('./isArray');
6
7 /**
8  * This method is like `_.find` except that it iterates over elements of
9  * `collection` from right to left.
10  *
11  * @static
12  * @memberOf _
13  * @category Collection
14  * @param {Array|Object} collection The collection to search.
15  * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
16  * @returns {*} Returns the matched element, else `undefined`.
17  * @example
18  *
19  * _.findLast([1, 2, 3, 4], function(n) {
20  *   return n % 2 == 1;
21  * });
22  * // => 3
23  */
24 function findLast(collection, predicate) {
25   predicate = baseIteratee(predicate, 3);
26   if (isArray(collection)) {
27     var index = baseFindIndex(collection, predicate, true);
28     return index > -1 ? collection[index] : undefined;
29   }
30   return baseFind(collection, predicate, baseEachRight);
31 }
32
33 module.exports = findLast;