Skip to content

Commit 8766ef0

Browse files
Time: 73 ms (25.97%), Space: 44.7 MB (60.45%) - LeetHub
1 parent 5b0ffc6 commit 8766ef0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2789-counter-ii/2789-counter-ii.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {integer} init
3+
* @return { increment: Function, decrement: Function, reset: Function }
4+
*/
5+
var createCounter = function(init) {
6+
let initCount = init;
7+
return {
8+
increment: () => {return ++initCount},
9+
decrement: () => {return --initCount},
10+
reset: () => {
11+
initCount = init;
12+
return initCount;}
13+
}
14+
};
15+
16+
/**
17+
* const counter = createCounter(5)
18+
* counter.increment(); // 6
19+
* counter.reset(); // 5
20+
* counter.decrement(); // 4
21+
*/

0 commit comments

Comments
 (0)