Created
October 28, 2015 13:27
-
-
Save trungdq88/28d03efc73f7e93a19a0 to your computer and use it in GitHub Desktop.
calc(1)(2)(3)() = 6, calc(1)(1)(1)(1)() = 4, calc(a)(b)(c)...(z) = a + b + c + ... + z, find the calc function. Guys, let me know your solution.
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
<script> | |
var calc = function () { | |
var value = (this instanceof Number ? +this : 0); | |
if (!arguments.length) return value; | |
return calc.bind(arguments[0] + value); | |
} | |
console.log(calc(1)(8)(3)(99)()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment