baseIndexOf.js 678 B

123456789101112131415161718192021222324252627
  1. var indexOfNaN = require('./indexOfNaN');
  2. /**
  3. * The base implementation of `_.indexOf` without support for binary searches.
  4. *
  5. * @private
  6. * @param {Array} array The array to search.
  7. * @param {*} value The value to search for.
  8. * @param {number} fromIndex The index to search from.
  9. * @returns {number} Returns the index of the matched value, else `-1`.
  10. */
  11. function baseIndexOf(array, value, fromIndex) {
  12. if (value !== value) {
  13. return indexOfNaN(array, fromIndex);
  14. }
  15. var index = fromIndex - 1,
  16. length = array.length;
  17. while (++index < length) {
  18. if (array[index] === value) {
  19. return index;
  20. }
  21. }
  22. return -1;
  23. }
  24. module.exports = baseIndexOf;