Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Multiplier via Closure

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 144: Closures

Implement `multiplyWith(factor, n)` that uses a closure internally: create a function that multiplies by `factor`, then apply it to `n` and return the result.

Sample tests

Input: multiplyWith(3, 4)
Output: 12
Input: multiplyWith(5, 0)
Output: 0

+ 2 hidden tests run on Submit.

Hints

Common pitfalls
  • Reading the factor from outside instead of capturing it.

Learning resources

  • MDN: Closures
Approach & explanation (try first)

The returned multiplier captures factor by closure and applies it to each value.

Loading...
⌘/Ctrl + Enter

Run your code to see results.