e-index-of.js 934 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. var numberIsNaN = require("../../number/is-nan")
  3. , toPosInt = require("../../number/to-pos-integer")
  4. , value = require("../../object/valid-value")
  5. , indexOf = Array.prototype.indexOf
  6. , objHasOwnProperty = Object.prototype.hasOwnProperty
  7. , abs = Math.abs
  8. , floor = Math.floor;
  9. module.exports = function (searchElement /*, fromIndex*/) {
  10. var i, length, fromIndex, val;
  11. if (!numberIsNaN(searchElement)) return indexOf.apply(this, arguments);
  12. length = toPosInt(value(this).length);
  13. fromIndex = arguments[1];
  14. if (isNaN(fromIndex)) fromIndex = 0;
  15. else if (fromIndex >= 0) fromIndex = floor(fromIndex);
  16. else fromIndex = toPosInt(this.length) - floor(abs(fromIndex));
  17. for (i = fromIndex; i < length; ++i) {
  18. if (objHasOwnProperty.call(this, i)) {
  19. val = this[i];
  20. if (numberIsNaN(val)) return i; // Jslint: ignore
  21. }
  22. }
  23. return -1;
  24. };