Skip to content

Instantly share code, notes, and snippets.

@trungdq88
Created October 28, 2015 13:27
Show Gist options
  • Save trungdq88/28d03efc73f7e93a19a0 to your computer and use it in GitHub Desktop.
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.
<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