source: imaps-frontend/node_modules/lodash-es/lastIndexOf.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import baseFindIndex from './_baseFindIndex.js';
2import baseIsNaN from './_baseIsNaN.js';
3import strictLastIndexOf from './_strictLastIndexOf.js';
4import toInteger from './toInteger.js';
5
6/* Built-in method references for those with the same name as other `lodash` methods. */
7var nativeMax = Math.max,
8 nativeMin = Math.min;
9
10/**
11 * This method is like `_.indexOf` except that it iterates over elements of
12 * `array` from right to left.
13 *
14 * @static
15 * @memberOf _
16 * @since 0.1.0
17 * @category Array
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`.
22 * @example
23 *
24 * _.lastIndexOf([1, 2, 1, 2], 2);
25 * // => 3
26 *
27 * // Search from the `fromIndex`.
28 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
29 * // => 1
30 */
31function lastIndexOf(array, value, fromIndex) {
32 var length = array == null ? 0 : array.length;
33 if (!length) {
34 return -1;
35 }
36 var index = length;
37 if (fromIndex !== undefined) {
38 index = toInteger(fromIndex);
39 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
40 }
41 return value === value
42 ? strictLastIndexOf(array, value, index)
43 : baseFindIndex(array, baseIsNaN, index, true);
44}
45
46export default lastIndexOf;
Note: See TracBrowser for help on using the repository browser.