Skip to content

Instantly share code, notes, and snippets.

@clintonhalpin
Last active August 29, 2015 14:07
Show Gist options
  • Save clintonhalpin/d737599a0970054e7934 to your computer and use it in GitHub Desktop.
Save clintonhalpin/d737599a0970054e7934 to your computer and use it in GitHub Desktop.
Filtering Test
var Items = [
{ name: 'Nasir Jones', gender : 'm' },
{ name: 'Mike Jones', gender : 'm' },
{ name: 'Lil Kim', gender : 'f' }
];
// No more for loops, Add as many args to CHANGEME
function filter(fn, list) {
var idx = -1, len = list.length, result = [];
while (++idx < len) {
if (fn(list[idx])) {
result.push(list[idx]);
}
}
return result;
};
function CHANGEME() {}
var mike = filter(CHANGEME('Mike Jones'), Items);
// => 'Mike Jones'
var guys = filter(CHANGEME('m'), Items);
guys.length === 2;
// => True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment