Skip to content

Commit

Permalink
Time: 60 ms (52.01%), Space: 50.8 MB (97.92%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
joseantoniochacon committed Jun 19, 2024
1 parent 963db26 commit 5d60d73
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 2665-counter-ii/2665-counter-ii.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @param {integer} init
* @return { increment: Function, decrement: Function, reset: Function }
*/
var createCounter = function(init) {
let count = init;

return {
increment() {
count += 1;
return count;
},
decrement() {
count -= 1;
return count;
},
reset() {
count = init;
return count;
}
};
};

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

0 comments on commit 5d60d73

Please sign in to comment.