Skip to content

Instantly share code, notes, and snippets.

@dolvik
Created September 2, 2016 06:54
Show Gist options
  • Save dolvik/8551d356e418bbc96dd8ee15543bd3fd to your computer and use it in GitHub Desktop.
Save dolvik/8551d356e418bbc96dd8ee15543bd3fd to your computer and use it in GitHub Desktop.
JS functional calc
var five = num(5);
var one = num(1);
console.log(five(plus(one()))); //6
function plus(arg){
return function(arg2){
return arg + arg2;
}
}
function num(val){
return function(func){
if (func === undefined){
return val;
}
return func(val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment