-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-includes.js
More file actions
30 lines (30 loc) · 778 Bytes
/
array-includes.js
File metadata and controls
30 lines (30 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
if (![].includes) {
Array.prototype.includes = function (searchElement, fromIndex) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(fromIndex) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
while (k < len) {
var currentElement = O[k];
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)
) {
return true;
}
k++;
}
return false;
};
}