import _curry2 from "./internal/_curry2.js";
|
|
import _dispatchable from "./internal/_dispatchable.js";
|
|
import _xfindLastIndex from "./internal/_xfindLastIndex.js";
|
|
/**
|
|
* Returns the index of the last element of the list which matches the
|
|
* predicate, or `-1` if no element matches.
|
|
*
|
|
* Acts as a transducer if a transformer is given in list position.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.1.1
|
|
* @category List
|
|
* @sig (a -> Boolean) -> [a] -> Number
|
|
* @param {Function} fn The predicate function used to determine if the element is the
|
|
* desired one.
|
|
* @param {Array} list The array to consider.
|
|
* @return {Number} The index of the element found, or `-1`.
|
|
* @see R.transduce
|
|
* @example
|
|
*
|
|
* const xs = [{a: 1, b: 0}, {a:1, b: 1}];
|
|
* R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
|
|
* R.findLastIndex(R.propEq('a', 4))(xs); //=> -1
|
|
*/
|
|
|
|
var findLastIndex =
|
|
/*#__PURE__*/
|
|
_curry2(
|
|
/*#__PURE__*/
|
|
_dispatchable([], _xfindLastIndex, function findLastIndex(fn, list) {
|
|
var idx = list.length - 1;
|
|
|
|
while (idx >= 0) {
|
|
if (fn(list[idx])) {
|
|
return idx;
|
|
}
|
|
|
|
idx -= 1;
|
|
}
|
|
|
|
return -1;
|
|
}));
|
|
|
|
export default findLastIndex;
|