Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit ba1e582

Browse files
committed
Add polyfill for Array includes function. fixes #45
1 parent 0413090 commit ba1e582

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

runestone/common/js/runestonebase.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,33 @@ RunestoneBase.prototype.logRunEvent = function (info) {
1818
console.log("running " + eventInfo);
1919
};
2020

21+
22+
23+
if (![].includes) {
24+
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
25+
'use strict';
26+
var O = Object(this);
27+
var len = parseInt(O.length) || 0;
28+
if (len === 0) {
29+
return false;
30+
}
31+
var n = parseInt(arguments[1]) || 0;
32+
var k;
33+
if (n >= 0) {
34+
k = n;
35+
} else {
36+
k = len + n;
37+
if (k < 0) {k = 0;}
38+
}
39+
var currentElement;
40+
while (k < len) {
41+
currentElement = O[k];
42+
if (searchElement === currentElement ||
43+
(searchElement !== searchElement && currentElement !== currentElement)) {
44+
return true;
45+
}
46+
k++;
47+
}
48+
return false;
49+
};
50+
}

0 commit comments

Comments
 (0)