Skip to content

Instantly share code, notes, and snippets.

@privateblue
Created November 7, 2014 19:55
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 privateblue/59d3d3355b9f6cf3a66b to your computer and use it in GitHub Desktop.
Save privateblue/59d3d3355b9f6cf3a66b to your computer and use it in GitHub Desktop.
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