Skip to content

Instantly share code, notes, and snippets.

@tapmodo
Created October 22, 2014 23:41
Show Gist options
  • Save tapmodo/abeb506216baa17e6df8 to your computer and use it in GitHub Desktop.
Save tapmodo/abeb506216baa17e6df8 to your computer and use it in GitHub Desktop.
map and filter functions
// 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