Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Last active December 16, 2015 12:28
Show Gist options
  • Save Cycymomo/5434410 to your computer and use it in GitHub Desktop.
Save Cycymomo/5434410 to your computer and use it in GitHub Desktop.
Array filter
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */) {
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) if (i in t) {
var val = t[i];
if (fun.call(thisp, val, i, t))
res.push(val);
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment