Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created May 20, 2014 15:11
Show Gist options
  • Save Shinpeim/57333375e27bb522d217 to your computer and use it in GitHub Desktop.
Save Shinpeim/57333375e27bb522d217 to your computer and use it in GitHub Desktop.
function compose(f, g) {
return function(x){
return g(f(x));
}
}
var increment = function(x) {
return x + 1;
}
var decrement = function(x) {
return x - 1;
}
// increment のあとに decrement する関数を作る
var do_nothing = compose(increment, decrement);
console.log(do_nothing(10)); // => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment