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.1 KB
|
Line | |
---|
1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _isArray =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_isArray.js");
|
---|
8 |
|
---|
9 | var equals =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./equals.js");
|
---|
12 | /**
|
---|
13 | * Returns the position of the last occurrence of an item in an array, or -1 if
|
---|
14 | * the item is not included in the array. [`R.equals`](#equals) is used to
|
---|
15 | * determine equality.
|
---|
16 | *
|
---|
17 | * @func
|
---|
18 | * @memberOf R
|
---|
19 | * @since v0.1.0
|
---|
20 | * @category List
|
---|
21 | * @sig a -> [a] -> Number
|
---|
22 | * @param {*} target The item to find.
|
---|
23 | * @param {Array} xs The array to search in.
|
---|
24 | * @return {Number} the index of the target, or -1 if the target is not found.
|
---|
25 | * @see R.indexOf, R.findLastIndex
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
|
---|
29 | * R.lastIndexOf(10, [1,2,3,4]); //=> -1
|
---|
30 | */
|
---|
31 |
|
---|
32 |
|
---|
33 | var lastIndexOf =
|
---|
34 | /*#__PURE__*/
|
---|
35 | _curry2(function lastIndexOf(target, xs) {
|
---|
36 | if (typeof xs.lastIndexOf === 'function' && !_isArray(xs)) {
|
---|
37 | return xs.lastIndexOf(target);
|
---|
38 | } else {
|
---|
39 | var idx = xs.length - 1;
|
---|
40 |
|
---|
41 | while (idx >= 0) {
|
---|
42 | if (equals(xs[idx], target)) {
|
---|
43 | return idx;
|
---|
44 | }
|
---|
45 |
|
---|
46 | idx -= 1;
|
---|
47 | }
|
---|
48 |
|
---|
49 | return -1;
|
---|
50 | }
|
---|
51 | });
|
---|
52 |
|
---|
53 | module.exports = lastIndexOf; |
---|
Note:
See
TracBrowser
for help on using the repository browser.