Skip to content

Instantly share code, notes, and snippets.

@SergeyLipko
Last active April 19, 2017 10:44
Show Gist options
  • Save SergeyLipko/64a02678c4dffc3a1251438ade8a12b3 to your computer and use it in GitHub Desktop.
Save SergeyLipko/64a02678c4dffc3a1251438ade8a12b3 to your computer and use it in GitHub Desktop.
Handmade Array.prototype.filter()
const _arr = [
{ name: 'Mark', age: 21 },
{ name: 'Dan', age: 22 },
{ name: 'Zoe', age: 29 },
{ name: 'Victor', age: 21 },
{ name: 'Martin', age: 21 }
];
const filtered = _arr.filter(i => i.age === 21 );
const paramFunc = i => i.age === 21;
function customFilter(arr, callback, thisArg) {
let results = [];
for (let i = 0; i < arr.length; i++) {
if (callback.call(thisArg, arr[i])) {
results.push(arr[i]);
}
}
return results;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment