1 var binaryIndex = require('../internal/binaryIndex'),
2 indexOfNaN = require('../internal/indexOfNaN');
4 /* Native method references for those with the same name as other `lodash` methods. */
5 var nativeMax = Math.max,
9 * This method is like `_.indexOf` except that it iterates over elements of
10 * `array` from right to left.
15 * @param {Array} array The array to search.
16 * @param {*} value The value to search for.
17 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
18 * or `true` to perform a binary search on a sorted array.
19 * @returns {number} Returns the index of the matched value, else `-1`.
22 * _.lastIndexOf([1, 2, 1, 2], 2);
25 * // using `fromIndex`
26 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
29 * // performing a binary search
30 * _.lastIndexOf([1, 1, 2, 2], 2, true);
33 function lastIndexOf(array, value, fromIndex) {
34 var length = array ? array.length : 0;
39 if (typeof fromIndex == 'number') {
40 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
41 } else if (fromIndex) {
42 index = binaryIndex(array, value, true) - 1;
43 var other = array[index];
44 if (value === value ? (value === other) : (other !== other)) {
49 if (value !== value) {
50 return indexOfNaN(array, index, true);
53 if (array[index] === value) {
60 module.exports = lastIndexOf;