Created
February 5, 2014 16:04
-
-
Save slopeofhope81/8826927 to your computer and use it in GitHub Desktop.
write a map and forEach function
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
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