Created
January 30, 2014 03:05
-
-
Save sranso/8701793 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
<html> | |
<script type="text/javascript"> | |
function each(array, f) { | |
var new_array = [] | |
for (i = 0; i < array.length; i++) { | |
new_array.push(f(array[i])) | |
} | |
return new_array | |
} | |
function addTwo(element) { | |
return element + 2 | |
} | |
var array = [1,2,3] | |
var result = each(array, addTwo) | |
console.log(result) | |
</script> | |
</html> | |
<!-- point: just like we can build each in ruby, we can build each in js --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment