Skip to content

Commit

Permalink
Time: 73 ms (25.97%), Space: 44.7 MB (60.45%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
harmeetsingh11 committed May 8, 2023
1 parent 5b0ffc6 commit 8766ef0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 2789-counter-ii/2789-counter-ii.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @param {integer} init
* @return { increment: Function, decrement: Function, reset: Function }
*/
var createCounter = function(init) {
let initCount = init;
return {
increment: () => {return ++initCount},
decrement: () => {return --initCount},
reset: () => {
initCount = init;
return initCount;}
}
};

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

0 comments on commit 8766ef0

Please sign in to comment.