mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/lastIndexOf.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
import _isArray from './internal/_isArray.js';
|
|
import equals from './equals.js';
|
|
|
|
|
|
/**
|
|
* Returns the position of the last occurrence of an item in an array, or -1 if
|
|
* the item is not included in the array. [`R.equals`](#equals) is used to
|
|
* determine equality.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.1.0
|
|
* @category List
|
|
* @sig a -> [a] -> Number
|
|
* @param {*} target The item to find.
|
|
* @param {Array} xs The array to search in.
|
|
* @return {Number} the index of the target, or -1 if the target is not found.
|
|
* @see R.indexOf
|
|
* @example
|
|
*
|
|
* R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
|
|
* R.lastIndexOf(10, [1,2,3,4]); //=> -1
|
|
*/
|
|
var lastIndexOf = _curry2(function lastIndexOf(target, xs) {
|
|
if (typeof xs.lastIndexOf === 'function' && !_isArray(xs)) {
|
|
return xs.lastIndexOf(target);
|
|
} else {
|
|
var idx = xs.length - 1;
|
|
while (idx >= 0) {
|
|
if (equals(xs[idx], target)) {
|
|
return idx;
|
|
}
|
|
idx -= 1;
|
|
}
|
|
return -1;
|
|
}
|
|
});
|
|
export default lastIndexOf;
|