Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2015 15:43
Show Gist options
  • Save anonymous/04067dff73e7e92e467d to your computer and use it in GitHub Desktop.
Save anonymous/04067dff73e7e92e467d to your computer and use it in GitHub Desktop.
var input = [1, 2, 3, 4, 5, 6];
function isEven(x){
return x % 2 == 0;
}
function filter(input, fn){
var output = [];
for(var i=0; i < input.length; i++){
if(fn(input[i])){ output.push(input[i]); }
}
return output;
}
console.log(filter(input, isEven));
console.log(input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment