mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Bump to v4.13.0.
This commit is contained in:
23
findIndex.js
23
findIndex.js
@@ -1,5 +1,9 @@
|
||||
import baseFindIndex from './_baseFindIndex';
|
||||
import baseIteratee from './_baseIteratee';
|
||||
import baseFindIndex from './_baseFindIndex.js';
|
||||
import baseIteratee from './_baseIteratee.js';
|
||||
import toInteger from './toInteger.js';
|
||||
|
||||
/* 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
|
||||
@@ -12,6 +16,7 @@ import baseIteratee from './_baseIteratee';
|
||||
* @param {Array} array The array to search.
|
||||
* @param {Array|Function|Object|string} [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
|
||||
*
|
||||
@@ -36,10 +41,16 @@ import baseIteratee from './_baseIteratee';
|
||||
* _.findIndex(users, 'active');
|
||||
* // => 2
|
||||
*/
|
||||
function findIndex(array, predicate) {
|
||||
return (array && array.length)
|
||||
? baseFindIndex(array, baseIteratee(predicate, 3))
|
||||
: -1;
|
||||
function findIndex(array, predicate, fromIndex) {
|
||||
var length = array ? array.length : 0;
|
||||
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);
|
||||
}
|
||||
|
||||
export default findIndex;
|
||||
|
||||
Reference in New Issue
Block a user