1
0

e-index-of.js 823 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var toPosInt = require('../../number/to-pos-integer')
  3. , value = require('../../object/valid-value')
  4. , indexOf = Array.prototype.indexOf
  5. , hasOwnProperty = Object.prototype.hasOwnProperty
  6. , abs = Math.abs, floor = Math.floor;
  7. module.exports = function (searchElement/*, fromIndex*/) {
  8. var i, l, fromIndex, val;
  9. if (searchElement === searchElement) { //jslint: ignore
  10. return indexOf.apply(this, arguments);
  11. }
  12. l = 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 < l; ++i) {
  18. if (hasOwnProperty.call(this, i)) {
  19. val = this[i];
  20. if (val !== val) return i; //jslint: ignore
  21. }
  22. }
  23. return -1;
  24. };