function makeMultiplier(n) {
return x => x * n
}
const double = makeMultiplier(2)
const triple = makeMultiplier(3)
double(5) // β 10
triple(5) // β 15Each call to the factory creates an independent closure capturing its own multiplier, so different instances never interfere with each other.
Create a factory function that produces multiplication functions.
Challenge: Create a makeMultiplier(n) function that returns a function. The returned function takes a value and returns the product of the preset value and the argument.
Example:
const mult4 = makeMultiplier(4)
mult4(7) // 28
mult4(3) // 12