Skip to content

Instantly share code, notes, and snippets.

@pjb3 pjb3/fib.js
Created May 11, 2009

Embed
What would you like to do?
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
You can’t perform that action at this time.