Sha256: 894101f1606411eeaa9be481ffda69c14ea8bff68811efd62db2dacd96dc31fb

Contents?: true

Size: 1.72 KB

Versions: 273

Compression:

Stored size: 1.72 KB

Contents

var baseFindIndex = require('./_baseFindIndex'),
    baseIteratee = require('./_baseIteratee'),
    toInteger = require('./toInteger');

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
    nativeMin = Math.min;

/**
 * This method is like `_.findIndex` except that it iterates over elements
 * of `collection` from right to left.
 *
 * @static
 * @memberOf _
 * @since 2.0.0
 * @category Array
 * @param {Array} array The array to inspect.
 * @param {Function} [predicate=_.identity] The function invoked per iteration.
 * @param {number} [fromIndex=array.length-1] The index to search from.
 * @returns {number} Returns the index of the found element, else `-1`.
 * @example
 *
 * var users = [
 *   { 'user': 'barney',  'active': true },
 *   { 'user': 'fred',    'active': false },
 *   { 'user': 'pebbles', 'active': false }
 * ];
 *
 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
 * // => 2
 *
 * // The `_.matches` iteratee shorthand.
 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
 * // => 0
 *
 * // The `_.matchesProperty` iteratee shorthand.
 * _.findLastIndex(users, ['active', false]);
 * // => 2
 *
 * // The `_.property` iteratee shorthand.
 * _.findLastIndex(users, 'active');
 * // => 0
 */
function findLastIndex(array, predicate, fromIndex) {
  var length = array == null ? 0 : array.length;
  if (!length) {
    return -1;
  }
  var index = length - 1;
  if (fromIndex !== undefined) {
    index = toInteger(fromIndex);
    index = fromIndex < 0
      ? nativeMax(length + index, 0)
      : nativeMin(index, length - 1);
  }
  return baseFindIndex(array, baseIteratee(predicate, 3), index, true);
}

module.exports = findLastIndex;

Version data entries

273 entries across 271 versions & 29 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.59 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.58 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.57 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.56 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.55 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.54 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.53 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.52 node_modules/lodash/findLastIndex.js
trusty-cms-6.3.1 node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.51 node_modules/lodash/findLastIndex.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/findLastIndex.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
immosquare-cleaner-0.1.50 node_modules/lodash/findLastIndex.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/findLastIndex.js