Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created January 19, 2020 01:11
Show Gist options
  • Save bitfishxyz/593b8ea5c3cb3320d60031880772a8be to your computer and use it in GitHub Desktop.
Save bitfishxyz/593b8ea5c3cb3320d60031880772a8be to your computer and use it in GitHub Desktop.
const selfFilter = function (fn, context) {
let arr = Array.prototype.slice.call(this)
let filteredArr = []
for (let i = 0; i < arr.length; i++) {
if(!arr.hasOwnProperty(i)) continue;
fn.call(context, arr[i], i, this) && filteredArr.push(arr[i])
}
return filteredArr
}
Array.prototype.selfFilter = selfFilter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment