-
-
Save rlemon/53701293e133ad797616 to your computer and use it in GitHub Desktop.
Array.prototype.filter2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.filter2 = function( | |
a, //a function to test each value of the array against. Truthy values will be put into the new array and falsey values will be excluded from the new array | |
b, // placeholder | |
c, // placeholder | |
d, // placeholder | |
e // placeholder | |
) { | |
c = this; // cache the array | |
d = []; // array to hold the new values which match the expression | |
for (e in c) // for each value in the array, | |
~~e + '' == e && e >= 0 && // coerce the array position and if valid, | |
a.call(b, c[e], +e, c) && // pass the current value into the expression and if truthy, | |
d.push(c[e]); // add it to the new array | |
return d // give back the new array | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment