Skip to content

Instantly share code, notes, and snippets.

@appositum
Last active April 21, 2018 07:19
Show Gist options
  • Save appositum/6d8a1f67ace306d26b3b76c781770a9d to your computer and use it in GitHub Desktop.
Save appositum/6d8a1f67ace306d26b3b76c781770a9d to your computer and use it in GitHub Desktop.
const soma = n => {
sum = n
const proxy = new Proxy(() => {}, {
get(obj, key) {
return () => {
if (sum) return sum
}
},
apply(receiver, ...args) {
if (args[1][0])
sum += args[1][0]
else
sum += 0
return proxy
},
})
return proxy
}
console.log(soma(1)(2)(3)(5)(4)(10)(20)) // 45
console.log(soma(1)(1)(1)(1)(1)(1)) // 6
console.log(soma(1)(1)(1)(1)(1)()(1)) // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment