FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Sum

15mins

Implement a function sum(num) that sums numbers by accepting a number and allows for repeated calling with more numbers until it is called without arguments.

The function should:

  • Accept a number and return a function that continues accumulating the sum.
  • When called without arguments, return the total sum.

Examples

sum(1)(2)(3)(); // 6 sum(10)(20)(30)(40)(); // 100 sum(5)(); // 5

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests