Private Gist
All pages are served over SSL and all pushing and pulling is done over SSH. No one may fork, clone, or view it unless they are given this private URL.
Every gist with this icon (
) is private.
Public Gist
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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]))
Please log in to comment.







