Facebook Pixel

Is the Amazon sum question a standard currying question?

It is a variation. Standard currying has a fixed number of arguments. The Amazon question allows infinite chaining with a custom termination (empty call or toString). It tests the same concepts (closures, function chaining) but requires a different termination mechanism.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Solving sum with a Generic Curry Function

The standard generic curry does not directly apply (it expects a fixed number of arguments). But you can adapt it for infinite chaining: function infiniteCurry(fn, initial) { return function(...args) { if (args.length === 0) return initial; return infiniteCurry(fn, fn(initial, ...args)); }; }

Generic curry expects a fixed number of arguments (fn.length) and calls the original when enough are collected. The Amazon sum allows infinite chaining and terminates on an empty call. The concept (closures, accumulation) is the same but the termination mechanism differs.

Instead of checking args.length >= fn.length, check if no arguments were passed (args.length === 0). If so, return the accumulated value. Otherwise, return a new curried function with the updated accumulator.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

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