4474d0cafd6a079dbb18f83e54bbe1c76f6469c0
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / indexOf.js
1 var baseIndexOf = require('./_baseIndexOf'),
2     toInteger = require('./toInteger');
3
4 /* Built-in method references for those with the same name as other `lodash` methods. */
5 var nativeMax = Math.max;
6
7 /**
8  * Gets the index at which the first occurrence of `value` is found in `array`
9  * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
10  * for equality comparisons. If `fromIndex` is negative, it's used as the offset
11  * from the end of `array`.
12  *
13  * @static
14  * @memberOf _
15  * @category Array
16  * @param {Array} array The array to search.
17  * @param {*} value The value to search for.
18  * @param {number} [fromIndex=0] The index to search from.
19  * @returns {number} Returns the index of the matched value, else `-1`.
20  * @example
21  *
22  * _.indexOf([1, 2, 1, 2], 2);
23  * // => 1
24  *
25  * // Search from the `fromIndex`.
26  * _.indexOf([1, 2, 1, 2], 2, 2);
27  * // => 3
28  */
29 function indexOf(array, value, fromIndex) {
30   var length = array ? array.length : 0;
31   if (!length) {
32     return -1;
33   }
34   fromIndex = toInteger(fromIndex);
35   if (fromIndex < 0) {
36     fromIndex = nativeMax(length + fromIndex, 0);
37   }
38   return baseIndexOf(array, value, fromIndex);
39 }
40
41 module.exports = indexOf;