Created
October 22, 2014 23:41
-
-
Save tapmodo/abeb506216baa17e6df8 to your computer and use it in GitHub Desktop.
map and filter functions
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
// map function | |
function array_map(arr,fn) { | |
var rv = []; | |
for(var i=0, l=arr.length; i<l; i++) | |
rv.push(fn(arr[i])); | |
return rv; | |
}; | |
// filter function | |
function array_filter(arr,fn) { | |
var rv = []; | |
for(var i=0, l=arr.length; i<l; i++) | |
if (fn(arr[i])) rv.push(arr[i]); | |
return rv; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment