Created
June 9, 2016 17:59
-
-
Save dolohow/edbc0337c050ed5def46c19d8ef73e9d 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 add(x, y) { | |
return x + y; | |
} | |
function mul(x, y) { | |
return x * y; | |
} | |
function make(arg) { | |
var arr = []; | |
arr.push(arg); | |
return function f(x) { | |
if (typeof x === 'number') { | |
arr.push(x); | |
return f; | |
} | |
return exec(x); | |
} | |
function exec(x) { | |
return arr.reduce(x); | |
} | |
} | |
var s = make(1)(2)(3)(4)(5); | |
console.log(s(add)); | |
console.log(s(mul)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment