Implement a function `createCounter(init)` that returns an object with three methods: `increment()`, `decrement()`, and `reset()`. These methods should manipulate a private variable initialized to `init` using JavaScript closures.
Examples
Example 1 Input:init = 5, actions: ["increment", "reset", "decrement"]
Output:[6, 5, 4]
Constraints
▪-1000 <= init <= 1000
Hints
Hint 1Show
Keep a local variable in the outer function scope to store the current value.
Hint 2Show
Return an object containing three functions that reference and modify this local variable.
Starter Code
Solution.js
1function createCounter(init) {
2 // Your code here
3}
Solution
Solve the problem first before reviewing the solution!