Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 10 additions & 39 deletions core/lib_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,15 @@
/************************* ARRAY *************************/


if (!Array.prototype.filter) {
Array.prototype.filter = function(func, thisArg) {
'use strict';
if (!((typeof func === 'Function' || typeof func === 'function') && this))
throw new TypeError();

var len = this.length >>> 0,
res = new Array(len), // preallocate array
t = this,
c = 0,
i = -1;

var kValue;
if (thisArg === undefined) {
while (++i !== len) {
// checks to see if the key was set
if (i in this) {
kValue = t[i]; // in case t is changed in callback
if (func(t[i], i, t)) {
res[c++] = kValue;
}
}
}
} else {
while (++i !== len) {
// checks to see if the key was set
if (i in this) {
kValue = t[i];
if (func.call(thisArg, t[i], i, t)) {
res[c++] = kValue;
}
}
}
}

res.length = c; // shrink down array to proper size
return res;
};
Array.prototype.filter = function(fn) {
var a = [];
for (var i = 0; i < this.length; i++) {
var n = fn(this[i]);
if (n) {
a.push(this[i]);
}
}
return a;
}


Expand Down Expand Up @@ -461,4 +432,4 @@
}());
}

</script>
</script>