Sha256: 561b38700412783a579bdcdfab83708ab863708d2f900c38f5e92bb2855a418a

Contents?: true

Size: 1.62 KB

Versions: 264

Compression:

Stored size: 1.62 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;

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

module.exports = findIndex;

Version data entries

264 entries across 262 versions & 29 rubygems

Version Path
appmap-0.71.0 ./node_modules/lodash/findIndex.js
disco_app-0.16.1 test/dummy/node_modules/lodash/findIndex.js
appmap-0.70.2 ./node_modules/lodash/findIndex.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/lodash/findIndex.js
appmap-0.70.1 ./node_modules/lodash/findIndex.js
appmap-0.70.0 ./node_modules/lodash/findIndex.js
appmap-0.69.0 ./node_modules/lodash/findIndex.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/lodash/findIndex.js
appmap-0.68.2 ./node_modules/lodash/findIndex.js
appmap-0.68.1 ./node_modules/lodash/findIndex.js
disco_app-0.15.2 test/dummy/node_modules/lodash/findIndex.js
appmap-0.68.0 ./node_modules/lodash/findIndex.js
appmap-0.67.1 ./node_modules/lodash/findIndex.js
trusty-cms-5.0.3 node_modules/lodash/findIndex.js
trusty-cms-5.0.2 node_modules/lodash/findIndex.js
appmap-0.67.0 ./node_modules/lodash/findIndex.js
disco_app-0.18.4 test/dummy/node_modules/lodash/findIndex.js
disco_app-0.18.1 test/dummy/node_modules/lodash/findIndex.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/lodash/findIndex.js
disco_app-0.14.0 test/dummy/node_modules/lodash/findIndex.js