1 | /**
|
2 | * lodash 3.1.0 (Custom Build) <https://lodash.com/>
|
3 | * Build: `lodash modern modularize exports="npm" -o ./`
|
4 | * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
5 | * Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
|
6 | * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
7 | * Available under MIT license <https://lodash.com/license>
|
8 | */
|
9 |
|
10 | /**
|
11 | * The base implementation of `_.indexOf` without support for binary searches.
|
12 | *
|
13 | * @private
|
14 | * @param {Array} array The array to search.
|
15 | * @param {*} value The value to search for.
|
16 | * @param {number} fromIndex The index to search from.
|
17 | * @returns {number} Returns the index of the matched value, else `-1`.
|
18 | */
|
19 | function baseIndexOf(array, value, fromIndex) {
|
20 | if (value !== value) {
|
21 | return indexOfNaN(array, fromIndex);
|
22 | }
|
23 | var index = fromIndex - 1,
|
24 | length = array.length;
|
25 |
|
26 | while (++index < length) {
|
27 | if (array[index] === value) {
|
28 | return index;
|
29 | }
|
30 | }
|
31 | return -1;
|
32 | }
|
33 |
|
34 | /**
|
35 | * Gets the index at which the first occurrence of `NaN` is found in `array`.
|
36 | * If `fromRight` is provided elements of `array` are iterated from right to left.
|
37 | *
|
38 | * @private
|
39 | * @param {Array} array The array to search.
|
40 | * @param {number} fromIndex The index to search from.
|
41 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
42 | * @returns {number} Returns the index of the matched `NaN`, else `-1`.
|
43 | */
|
44 | function indexOfNaN(array, fromIndex, fromRight) {
|
45 | var length = array.length,
|
46 | index = fromIndex + (fromRight ? 0 : -1);
|
47 |
|
48 | while ((fromRight ? index-- : ++index < length)) {
|
49 | var other = array[index];
|
50 | if (other !== other) {
|
51 | return index;
|
52 | }
|
53 | }
|
54 | return -1;
|
55 | }
|
56 |
|
57 | module.exports = baseIndexOf;
|