source: imaps-frontend/node_modules/array-includes/implementation.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
4var ToLength = require('es-abstract/2024/ToLength');
5var ToObject = require('es-object-atoms/ToObject');
6var SameValueZero = require('es-abstract/2024/SameValueZero');
7var $isNaN = require('es-abstract/helpers/isNaN');
8var $isFinite = require('es-abstract/helpers/isFinite');
9var GetIntrinsic = require('get-intrinsic');
10var callBound = require('call-bind/callBound');
11var isString = require('is-string');
12
13var $charAt = callBound('String.prototype.charAt');
14var $indexOf = GetIntrinsic('%Array.prototype.indexOf%'); // TODO: use callBind.apply without breaking IE 8
15var $max = GetIntrinsic('%Math.max%');
16
17module.exports = function includes(searchElement) {
18 var fromIndex = arguments.length > 1 ? ToIntegerOrInfinity(arguments[1]) : 0;
19 if ($indexOf && !$isNaN(searchElement) && $isFinite(fromIndex) && typeof searchElement !== 'undefined') {
20 return $indexOf.apply(this, arguments) > -1;
21 }
22
23 var O = ToObject(this);
24 var length = ToLength(O.length);
25 if (length === 0) {
26 return false;
27 }
28 var k = fromIndex >= 0 ? fromIndex : $max(0, length + fromIndex);
29 while (k < length) {
30 if (SameValueZero(searchElement, isString(O) ? $charAt(O, k) : O[k])) {
31 return true;
32 }
33 k += 1;
34 }
35 return false;
36};
Note: See TracBrowser for help on using the repository browser.