mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Coerce findLastIndex and lastIndexOf fromIndex parameter to integer (#4440)
* Enable lastIndexOf, findLast and findLastIndex * Coerce findLastIndex fromIndex parameter to integer * Coerce lastIndexOf fromIndex parameter to integer
This commit is contained in:
committed by
John-David Dalton
parent
ed4b3a2ddb
commit
3ebb38d389
@@ -1,4 +1,5 @@
|
||||
import baseFindIndex from './.internal/baseFindIndex.js'
|
||||
import toInteger from './toInteger.js'
|
||||
|
||||
/**
|
||||
* This method is like `findIndex` except that it iterates over elements
|
||||
@@ -29,9 +30,10 @@ function findLastIndex(array, predicate, fromIndex) {
|
||||
}
|
||||
let index = length - 1
|
||||
if (fromIndex !== undefined) {
|
||||
index = toInteger(fromIndex)
|
||||
index = fromIndex < 0
|
||||
? Math.max(length + fromIndex, 0)
|
||||
: Math.min(fromIndex, length - 1)
|
||||
? Math.max(length + index, 0)
|
||||
: Math.min(index, length - 1)
|
||||
}
|
||||
return baseFindIndex(array, predicate, index, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user