Created
November 7, 2014 19:55
-
-
Save privateblue/59d3d3355b9f6cf3a66b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simplefib(n) { | |
if (n <= 1) { | |
return n; | |
} else { | |
return fib(n - 1) + fib(n - 2); | |
} | |
} | |
function fib(n) { | |
var loop = function(i, acc, x) { | |
if (i <= 0) { | |
return acc; | |
} else { | |
return loop(i - 1, x, acc + x); | |
} | |
}; | |
return loop(n, 0, 1); | |
} | |
function isSorted(as, ordered) { | |
var loop = function(i, acc) { | |
if (i < as.length - 1 && acc) { | |
return loop(i + 1, ordered(as[i], as[i + 1])); | |
} else { | |
return acc; | |
} | |
}; | |
return loop(0, true); | |
} | |
function curry(f) { | |
return function(a) { | |
return function(b) { | |
return f(a, b); | |
} | |
} | |
} | |
function uncurry(f) { | |
return function(a, b) { | |
return f(a)(b); | |
} | |
} | |
function compose(f, g) { | |
return function(a) { | |
return f(g(a)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment