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