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