1 var baseFindIndex = require('./_baseFindIndex'),
2 baseIsNaN = require('./_baseIsNaN'),
3 strictLastIndexOf = require('./_strictLastIndexOf'),
4 toInteger = require('./toInteger');
6 /* Built-in method references for those with the same name as other `lodash` methods. */
7 var nativeMax = Math.max,
11 * This method is like `_.indexOf` except that it iterates over elements of
12 * `array` from right to left.
18 * @param {Array} array The array to inspect.
19 * @param {*} value The value to search for.
20 * @param {number} [fromIndex=array.length-1] The index to search from.
21 * @returns {number} Returns the index of the matched value, else `-1`.
24 * _.lastIndexOf([1, 2, 1, 2], 2);
27 * // Search from the `fromIndex`.
28 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
31 function lastIndexOf(array, value, fromIndex) {
32 var length = array == null ? 0 : array.length;
37 if (fromIndex !== undefined) {
38 index = toInteger(fromIndex);
39 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
41 return value === value
42 ? strictLastIndexOf(array, value, index)
43 : baseFindIndex(array, baseIsNaN, index, true);
46 module.exports = lastIndexOf;