aboutsummaryrefslogtreecommitdiff
path: root/node_modules/core-js/internals/array-includes.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/core-js/internals/array-includes.js')
-rw-r--r--node_modules/core-js/internals/array-includes.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/node_modules/core-js/internals/array-includes.js b/node_modules/core-js/internals/array-includes.js
new file mode 100644
index 0000000..a416120
--- /dev/null
+++ b/node_modules/core-js/internals/array-includes.js
@@ -0,0 +1,32 @@
+var toIndexedObject = require('../internals/to-indexed-object');
+var toLength = require('../internals/to-length');
+var toAbsoluteIndex = require('../internals/to-absolute-index');
+
+// `Array.prototype.{ indexOf, includes }` methods implementation
+var createMethod = function (IS_INCLUDES) {
+ return function ($this, el, fromIndex) {
+ var O = toIndexedObject($this);
+ var length = toLength(O.length);
+ var index = toAbsoluteIndex(fromIndex, length);
+ var value;
+ // Array#includes uses SameValueZero equality algorithm
+ // eslint-disable-next-line no-self-compare
+ if (IS_INCLUDES && el != el) while (length > index) {
+ value = O[index++];
+ // eslint-disable-next-line no-self-compare
+ if (value != value) return true;
+ // Array#indexOf ignores holes, Array#includes - not
+ } else for (;length > index; index++) {
+ if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
+ } return !IS_INCLUDES && -1;
+ };
+};
+
+module.exports = {
+ // `Array.prototype.includes` method
+ // https://tc39.github.io/ecma262/#sec-array.prototype.includes
+ includes: createMethod(true),
+ // `Array.prototype.indexOf` method
+ // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
+ indexOf: createMethod(false)
+};