Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 5, 2014 16:04
Show Gist options
  • Save slopeofhope81/8826927 to your computer and use it in GitHub Desktop.
Save slopeofhope81/8826927 to your computer and use it in GitHub Desktop.
write a map and forEach function
write a map and forEach function:
function forEach(array, action){
for (var i =0; i < array.length; i++){
action(array[i]));
}
};
function map(func,array){
var result =[];
forEach(array, function(element){
result.push(func(element));
});
};
*I was told that these functions are included in the global environment to all the browsers that support EMCAscript 5. But for some reason, it did not work using chrome so I had to write these functions individually to use the methods with reduce function!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment