Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created May 11, 2009 18:04
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 pjb3/110072 to your computer and use it in GitHub Desktop.
Save pjb3/110072 to your computer and use it in GitHub Desktop.
function each(f, arr) {
for(var i=0; i < arr.length; i++) {
f.apply(null, [arr[i]])
}
}
function map(f, arr) {
var result = []
each(function(e) {
result.push(f.apply(null, [e]))
}, arr)
return result
}
function fib(n) {
if(n <= 1) {
return n
} else {
return fib(n-1) + fib(n-2)
}
}
print("Double")
each(print, map(function(e){
return e * e
}, [1,2,3,4,5]))
print("\n")
print("Fib")
each(print, map(fib, [1,2,3,4,5,6,7,8,9,10]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment