Skip to content

Instantly share code, notes, and snippets.

@t3chnoboy
Created May 14, 2014 23:11
Show Gist options
  • Save t3chnoboy/d5bb55723c0e9034b45f to your computer and use it in GitHub Desktop.
Save t3chnoboy/d5bb55723c0e9034b45f to your computer and use it in GitHub Desktop.
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