mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Bump to v4.13.0.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
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,
|
||||
nativeMin = Math.min;
|
||||
|
||||
/**
|
||||
* This method is like `_.findIndex` except that it iterates over elements
|
||||
@@ -12,6 +17,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=array.length-1] The index to search from.
|
||||
* @returns {number} Returns the index of the found element, else `-1`.
|
||||
* @example
|
||||
*
|
||||
@@ -36,10 +42,19 @@ import baseIteratee from './_baseIteratee';
|
||||
* _.findLastIndex(users, 'active');
|
||||
* // => 0
|
||||
*/
|
||||
function findLastIndex(array, predicate) {
|
||||
return (array && array.length)
|
||||
? baseFindIndex(array, baseIteratee(predicate, 3), true)
|
||||
: -1;
|
||||
function findLastIndex(array, predicate, fromIndex) {
|
||||
var length = array ? array.length : 0;
|
||||
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);
|
||||
}
|
||||
|
||||
export default findLastIndex;
|
||||
|
||||
Reference in New Issue
Block a user