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
trusty-cms-6.3.1 node_modules/lodash/findIndex.js
immosquare-cleaner-0.1.51 node_modules/lodash/findIndex.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/findIndex.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/findIndex.js
immosquare-cleaner-0.1.50 node_modules/lodash/findIndex.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/lodash/findIndex.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/lodash/findIndex.js
immosquare-cleaner-0.1.49 node_modules/lodash/findIndex.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/lodash/findIndex.js
immosquare-cleaner-0.1.48 node_modules/lodash/findIndex.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/lodash/findIndex.js