Skip to content

Instantly share code, notes, and snippets.

@mfalade
Created September 8, 2018 06:25
Show Gist options
  • Save mfalade/2af65a1ab9d0219c64139267e9d49f04 to your computer and use it in GitHub Desktop.
Save mfalade/2af65a1ab9d0219c64139267e9d49f04 to your computer and use it in GitHub Desktop.
Basic Implementation of the array filter
Array.prototype.xfilter = myCustomArrayFilter;
function myCustomArrayFilter (action) {
var result = [];
for (var i = 0; i < this.length; i++) {
var args = [this[i], i, this];
if (action.apply(null, args)) {
result.push(this[i]);
}
}
return result;
}
var greaterThen4 = [4, 5, 6].xfilter(x => x > 4);
console.log(greaterThen4, 'filter')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment