git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

findLastKey.js (1999B)


      1 var baseCallback = require('../internal/baseCallback'),
      2     baseFind = require('../internal/baseFind'),
      3     baseForOwnRight = require('../internal/baseForOwnRight');
      4 
      5 /**
      6  * This method is like `_.findKey` except that it iterates over elements of
      7  * a collection in the opposite order.
      8  *
      9  * If a property name is provided for `predicate` the created `_.property`
     10  * style callback returns the property value of the given element.
     11  *
     12  * If a value is also provided for `thisArg` the created `_.matchesProperty`
     13  * style callback returns `true` for elements that have a matching property
     14  * value, else `false`.
     15  *
     16  * If an object is provided for `predicate` the created `_.matches` style
     17  * callback returns `true` for elements that have the properties of the given
     18  * object, else `false`.
     19  *
     20  * @static
     21  * @memberOf _
     22  * @category Object
     23  * @param {Object} object The object to search.
     24  * @param {Function|Object|string} [predicate=_.identity] The function invoked
     25  *  per iteration.
     26  * @param {*} [thisArg] The `this` binding of `predicate`.
     27  * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
     28  * @example
     29  *
     30  * var users = {
     31  *   'barney':  { 'age': 36, 'active': true },
     32  *   'fred':    { 'age': 40, 'active': false },
     33  *   'pebbles': { 'age': 1,  'active': true }
     34  * };
     35  *
     36  * _.findLastKey(users, function(chr) {
     37  *   return chr.age < 40;
     38  * });
     39  * // => returns `pebbles` assuming `_.findKey` returns `barney`
     40  *
     41  * // using the `_.matches` callback shorthand
     42  * _.findLastKey(users, { 'age': 36, 'active': true });
     43  * // => 'barney'
     44  *
     45  * // using the `_.matchesProperty` callback shorthand
     46  * _.findLastKey(users, 'active', false);
     47  * // => 'fred'
     48  *
     49  * // using the `_.property` callback shorthand
     50  * _.findLastKey(users, 'active');
     51  * // => 'pebbles'
     52  */
     53 function findLastKey(object, predicate, thisArg) {
     54   predicate = baseCallback(predicate, thisArg, 3);
     55   return baseFind(object, predicate, baseForOwnRight, true);
     56 }
     57 
     58 module.exports = findLastKey;