Question Bank

JavaScript Add-N via Currying: Two Approaches Quiz

Difficulty: Medium

Two seeded ways to build an `adder(n)` that adds `n` to its argument (closure-returning-function and `Function.prototype.bind`), plus two companions on three-arg currying and a generic curry helper.

Question Bank
/

JavaScript Add-N via Currying: Two Approaches Quiz

JavaScript Add-N via Currying: Two Approaches Quiz

Two seeded ways to build an `adder(n)` that adds `n` to its argument (closure-returning-function and `Function.prototype.bind`), plus two companions on three-arg currying and a generic curry helper.

Question Bank
Medium
JavaScript
4 questions
quiz
currying
closures
higher-order-functions

629 views

16

Implement adder(n) so it returns a function that adds n to its argument. Use the classic closure-returning-function pattern.

Examples

Example 1:

Input:
const adder5 = adder(5);
console.log(adder5(3));
console.log(adder(5)(3));
Output:
8
8
Explanation: adder(5) captures n = 5 in a closure and returns a function that adds 5 to whatever it receives.