Facebook Pixel
sum(1)(2)(3) Interview Tips for Amazon

How should I approach the sum(1)(2)(3) Amazon question in an interview?

The answer

Recognize it as currying. Start with the simple solution (terminate with empty call). Explain how closures accumulate the sum. Mention toString as an alternative. Handle follow-ups like multiple arguments.

More FAQs in sum(1)(2)(3) Interview Tips for Amazon

Not returning a function (the chain breaks), not accumulating the previous value, no termination mechanism (no way to get the result), and overcomplicating (using classes or complex state instead of a simple closure).

Yes. After the basic solution, mention that you could also use toString or valueOf for automatic type coercion. This shows deeper JavaScript knowledge (type coercion, toString, valueOf).

Step by step: sum(1) returns a function with a=1. Calling it with 2 returns sum(3) (a new function with a=3). Each call accumulates. Calling with no argument returns the accumulated sum. Each step uses a closure.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.