2
0

e-last-index-of.js 838 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var toPosInt = require('../../number/to-pos-integer')
  3. , value = require('../../object/valid-value')
  4. , lastIndexOf = Array.prototype.lastIndexOf
  5. , hasOwnProperty = Object.prototype.hasOwnProperty
  6. , abs = Math.abs, floor = Math.floor;
  7. module.exports = function (searchElement/*, fromIndex*/) {
  8. var i, fromIndex, val;
  9. if (searchElement === searchElement) { //jslint: ignore
  10. return lastIndexOf.apply(this, arguments);
  11. }
  12. value(this);
  13. fromIndex = arguments[1];
  14. if (isNaN(fromIndex)) fromIndex = (toPosInt(this.length) - 1);
  15. else if (fromIndex >= 0) fromIndex = floor(fromIndex);
  16. else fromIndex = toPosInt(this.length) - floor(abs(fromIndex));
  17. for (i = fromIndex; i >= 0; --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. };