Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created July 22, 2013 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/53701293e133ad797616 to your computer and use it in GitHub Desktop.
Save rlemon/53701293e133ad797616 to your computer and use it in GitHub Desktop.
Array.prototype.filter2
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