Skip to content

Instantly share code, notes, and snippets.

@sranso
Created January 30, 2014 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sranso/8701793 to your computer and use it in GitHub Desktop.
Save sranso/8701793 to your computer and use it in GitHub Desktop.
<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