react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / array / indexOf.js
80742 viewsvar baseIndexOf = require('../internal/baseIndexOf'),1binaryIndex = require('../internal/binaryIndex');23/* Native method references for those with the same name as other `lodash` methods. */4var nativeMax = Math.max;56/**7* Gets the index at which the first occurrence of `value` is found in `array`8* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)9* for equality comparisons. If `fromIndex` is negative, it is used as the offset10* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`11* performs a faster binary search.12*13* @static14* @memberOf _15* @category Array16* @param {Array} array The array to search.17* @param {*} value The value to search for.18* @param {boolean|number} [fromIndex=0] The index to search from or `true`19* to perform a binary search on a sorted array.20* @returns {number} Returns the index of the matched value, else `-1`.21* @example22*23* _.indexOf([1, 2, 1, 2], 2);24* // => 125*26* // using `fromIndex`27* _.indexOf([1, 2, 1, 2], 2, 2);28* // => 329*30* // performing a binary search31* _.indexOf([1, 1, 2, 2], 2, true);32* // => 233*/34function indexOf(array, value, fromIndex) {35var length = array ? array.length : 0;36if (!length) {37return -1;38}39if (typeof fromIndex == 'number') {40fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;41} else if (fromIndex) {42var index = binaryIndex(array, value),43other = array[index];4445if (value === value ? (value === other) : (other !== other)) {46return index;47}48return -1;49}50return baseIndexOf(array, value, fromIndex || 0);51}5253module.exports = indexOf;545556