Explorer
Node.js

Write a function `createCounter(start)` that returns an object with `increment()`, `decrement()`, and `getCount()` methods using closure.

Problem Statement

Write a function `createCounter(start)` that returns an object with `increment()`, `decrement()`, and `getCount()` methods using closure.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Closures capture variables from the enclosing scope. šŸ’” Hint 2: The counter variable persists between calls because of closure. šŸ’” Hint 3: let count = start; return { increment: () => ++count, decrement: () => --count, getCount: () => count }; āœ… Solution: ```javascript function createCounter(start) { let count = start; return { increment: () => ++count, decrement: () => --count, getCount: () => count }; } ```

Closure Counter

Easy
Write a function `createCounter(start)` that returns an object with `increment()`, `decrement()`, and `getCount()` methods using closure.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
2