Last active
April 21, 2018 07:19
-
-
Save appositum/6d8a1f67ace306d26b3b76c781770a9d 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
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