source: node_modules/ramda/src/findIndex.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var _dispatchable =
6/*#__PURE__*/
7require("./internal/_dispatchable.js");
8
9var _xfindIndex =
10/*#__PURE__*/
11require("./internal/_xfindIndex.js");
12/**
13 * Returns the index of the first 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, R.indexOf
28 * @example
29 *
30 * const xs = [{a: 1}, {a: 2}, {a: 3}];
31 * R.findIndex(R.propEq(2, 'a'))(xs); //=> 1
32 * R.findIndex(R.propEq(4, 'a'))(xs); //=> -1
33 */
34
35
36var findIndex =
37/*#__PURE__*/
38_curry2(
39/*#__PURE__*/
40_dispatchable([], _xfindIndex, function findIndex(fn, list) {
41 var idx = 0;
42 var len = list.length;
43
44 while (idx < len) {
45 if (fn(list[idx])) {
46 return idx;
47 }
48
49 idx += 1;
50 }
51
52 return -1;
53}));
54
55module.exports = findIndex;
Note: See TracBrowser for help on using the repository browser.