Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function mapReduce(map, reduce, zero){
return function loop(from, to){
if(from > to){
return zero;
return reduce(map(from), loop(from + 1, to));
function mult(a, b){
return a * b;
function id(a){
return a;
function fact(n){
return mapReduce(id, mult, 1)(1, n);
function gcd(a, b){
return b === 0 ? a : gcd(a, b % a);
gcd(2, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment