Created
May 14, 2014 23:11
-
-
Save t3chnoboy/d5bb55723c0e9034b45f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var add = function(x, y) { return x + y } | |
var mul = function(x, y) { return x * y } | |
var make = function(x, arr) { | |
if (typeof x == 'number') { | |
arr ? arr.push(x) : arr = [x] | |
return function(x) { return make(x, arr) } | |
} else return arr.reduce(x) | |
} | |
var make = function(x, arr) { | |
return typeof x == 'number' | |
? (arr ? arr.push(x) : arr = [x], function(x) { return make(x, arr) }) | |
: arr.reduce(x) | |
} | |
var s = make(1)(2)(3)(4)(5) | |
s(add) // => 15 | |
console.log(s(mul)) // => 120 | |
var x = make(5)(10)(15) | |
x(add) // => 30 | |
x(mul) // => 750 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment