1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _dispatchable =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_dispatchable");
|
8 |
|
9 | var _xfindLastIndex =
|
10 | /*#__PURE__*/
|
11 | require("./internal/_xfindLastIndex");
|
12 | /**
|
13 | * Returns the index of the last element of the list which matches the
|
14 | * predicate, or `-1` if no element matches.
|
15 | *
|
16 | * Acts as a transducer if a transformer is given in list position.
|
17 | *
|
18 | * @func
|
19 | * @memberOf R
|
20 | * @since v0.1.1
|
21 | * @category List
|
22 | * @sig (a -> Boolean) -> [a] -> Number
|
23 | * @param {Function} fn The predicate function used to determine if the element is the
|
24 | * desired one.
|
25 | * @param {Array} list The array to consider.
|
26 | * @return {Number} The index of the element found, or `-1`.
|
27 | * @see R.transduce
|
28 | * @example
|
29 | *
|
30 | * const xs = [{a: 1, b: 0}, {a:1, b: 1}];
|
31 | * R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
|
32 | * R.findLastIndex(R.propEq('a', 4))(xs); //=> -1
|
33 | */
|
34 |
|
35 |
|
36 | var findLastIndex =
|
37 | /*#__PURE__*/
|
38 | _curry2(
|
39 | /*#__PURE__*/
|
40 | _dispatchable([], _xfindLastIndex, function findLastIndex(fn, list) {
|
41 | var idx = list.length - 1;
|
42 |
|
43 | while (idx >= 0) {
|
44 | if (fn(list[idx])) {
|
45 | return idx;
|
46 | }
|
47 |
|
48 | idx -= 1;
|
49 | }
|
50 |
|
51 | return -1;
|
52 | }));
|
53 |
|
54 | module.exports = findLastIndex; |
\ | No newline at end of file |