Created
April 18, 2015 15:43
-
-
Save anonymous/04067dff73e7e92e467d to your computer and use it in GitHub Desktop.
This file contains 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 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