Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

array-includes.js 1.3KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var toIndexedObject = require('../internals/to-indexed-object');
  3. var toAbsoluteIndex = require('../internals/to-absolute-index');
  4. var lengthOfArrayLike = require('../internals/length-of-array-like');
  5. // `Array.prototype.{ indexOf, includes }` methods implementation
  6. var createMethod = function (IS_INCLUDES) {
  7. return function ($this, el, fromIndex) {
  8. var O = toIndexedObject($this);
  9. var length = lengthOfArrayLike(O);
  10. if (length === 0) return !IS_INCLUDES && -1;
  11. var index = toAbsoluteIndex(fromIndex, length);
  12. var value;
  13. // Array#includes uses SameValueZero equality algorithm
  14. // eslint-disable-next-line no-self-compare -- NaN check
  15. if (IS_INCLUDES && el !== el) while (length > index) {
  16. value = O[index++];
  17. // eslint-disable-next-line no-self-compare -- NaN check
  18. if (value !== value) return true;
  19. // Array#indexOf ignores holes, Array#includes - not
  20. } else for (;length > index; index++) {
  21. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  22. } return !IS_INCLUDES && -1;
  23. };
  24. };
  25. module.exports = {
  26. // `Array.prototype.includes` method
  27. // https://tc39.es/ecma262/#sec-array.prototype.includes
  28. includes: createMethod(true),
  29. // `Array.prototype.indexOf` method
  30. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  31. indexOf: createMethod(false)
  32. };