implementation.js 851 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var ES = require('es-abstract/es6');
  3. var $isNaN = Number.isNaN || function isNaN(a) {
  4. return a !== a;
  5. };
  6. var $isFinite = Number.isFinite || function isFinite(n) {
  7. return typeof n === 'number' && global.isFinite(n);
  8. };
  9. var indexOf = Array.prototype.indexOf;
  10. module.exports = function includes(searchElement) {
  11. var fromIndex = arguments.length > 1 ? ES.ToInteger(arguments[1]) : 0;
  12. if (indexOf && !$isNaN(searchElement) && $isFinite(fromIndex) && typeof searchElement !== 'undefined') {
  13. return indexOf.apply(this, arguments) > -1;
  14. }
  15. var O = ES.ToObject(this);
  16. var length = ES.ToLength(O.length);
  17. if (length === 0) {
  18. return false;
  19. }
  20. var k = fromIndex >= 0 ? fromIndex : Math.max(0, length + fromIndex);
  21. while (k < length) {
  22. if (ES.SameValueZero(searchElement, O[k])) {
  23. return true;
  24. }
  25. k += 1;
  26. }
  27. return false;
  28. };