Skip to content

Commit

Permalink
Time: 48 ms (95.64%) | Memory: 51.7 MB (52.95%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
nitesh2920 committed Jan 4, 2025
1 parent 81cd646 commit 43b7a1f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 2789-counter-ii/counter-ii.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @param {integer} init
* @return { increment: Function, decrement: Function, reset: Function }
*/
var createCounter = function(init) {
let initial=init;
return{
increment:()=>{
return ++init;
},
decrement:()=>{
return --init;

},
reset:()=>{
init=initial;
return init;

}

}

};

/**
* const counter = createCounter(5)
* counter.increment(); // 6
* counter.reset(); // 5
* counter.decrement(); // 4
*/

0 comments on commit 43b7a1f

Please sign in to comment.