[image]
pjb3 (owner)

Revisions

88863e pjb3 August 05, 2009 4452fe May 11, 2009
gist: 110072 Download_button fork
public
public
Public Clone URL: git://gist.github.com/110072.git
Give this clone URL to anyone.
git clone git://gist.github.com/110072.git gist-110072
Embed All Files: show embed
fib.js #
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.


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser