UNPKG

874 BJavaScriptView Raw
1/* tslint:disable */
2/* eslint-disable no-extend-native */
3/* eslint-disable valid-typeof */
4
5if (!Array.prototype.filter)
6 Array.prototype.filter = function (func, thisArg) {
7 if (!((typeof func === 'Function' || typeof func === 'function') && this))
8 throw new TypeError();
9
10 var len = this.length >>> 0,
11 res = new Array(len), // preallocate array
12 t = this, c = 0, i = -1;
13 if (thisArg === undefined)
14 while (++i !== len)
15 // checks to see if the key was set
16 if (i in this)
17 if (func(t[i], i, t))
18 res[c++] = t[i];
19 else
20 while (++i !== len)
21 // checks to see if the key was set
22 if (i in this)
23 if (func.call(thisArg, t[i], i, t))
24 res[c++] = t[i];
25
26 res.length = c; // shrink down array to proper size
27 return res;
28 };
\No newline at end of file