Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
Sum
easy10 min
Accumulate numbers through repeated function calls and return the total when called with no arguments.
Requirements
Implement sum(...values). Each call with one or more numbers returns another callable collector; a call with no arguments returns the accumulated number. sum() alone returns 0.
Support multiple numbers per call, zero, negative numbers, and decimals. Assume finite numeric arguments; ordinary JavaScript arithmetic is sufficient.
Each collector retains its own total. Calling it with more numbers creates a new collector without changing the earlier collector, so independent branches and repeated reads are safe.
Keep state in closures rather than global variables. Separate top-level sum calls must remain independent.
No string coercion, valueOf conversion, asynchronous inputs, or implicit termination is required; the empty call explicitly ends a chain.