indexOfNaN.js 657 B

1234567891011121314151617181920212223
  1. /**
  2. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  3. *
  4. * @private
  5. * @param {Array} array The array to search.
  6. * @param {number} fromIndex The index to search from.
  7. * @param {boolean} [fromRight] Specify iterating from right to left.
  8. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  9. */
  10. function indexOfNaN(array, fromIndex, fromRight) {
  11. var length = array.length,
  12. index = fromIndex + (fromRight ? 0 : -1);
  13. while ((fromRight ? index-- : ++index < length)) {
  14. var other = array[index];
  15. if (other !== other) {
  16. return index;
  17. }
  18. }
  19. return -1;
  20. }
  21. module.exports = indexOfNaN;