Skip to content

Commit 0a23e45

Browse files
committed
Build: Add lib/array-polyfills.js
1 parent f68708f commit 0a23e45

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/array-polyfills.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// TODO: Add polyfill for Array.from
2+
3+
if (!Array.prototype.includes) {
4+
Array.prototype.includes = function(searchElement, fromIndex) {
5+
'use strict';
6+
if (!this) {
7+
throw new TypeError('Array.prototype.includes called on null or undefined');
8+
}
9+
10+
return this.indexOf(searchElement, fromIndex) !== -1;
11+
}
12+
}
13+
14+
if (!Array.prototype.every) {
15+
Array.prototype.every = function(func) {
16+
'use strict';
17+
let result = true;
18+
19+
this.forEach((item, index) => {
20+
if (!result) {
21+
return;
22+
} else if (!func(item, index, this)) {
23+
result = false;
24+
}
25+
});
26+
27+
return result;
28+
}
29+
}
30+
31+
if (!Array.prototype.some) {
32+
Array.prototype.some = function(func) {
33+
'use strict';
34+
let result = false;
35+
36+
this.forEach((item, index) => {
37+
if (result) {
38+
return;
39+
} else if (func(item, index, this)) {
40+
result = true;
41+
}
42+
});
43+
44+
return result;
45+
}
46+
}
47+
48+
export default Array;

0 commit comments

Comments
 (0)