Last active
August 29, 2015 14:07
-
-
Save clintonhalpin/d737599a0970054e7934 to your computer and use it in GitHub Desktop.
Filtering Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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