Skip to content

Commit 3bfab3d

Browse files
day 04 task complete
1 parent b2322ee commit 3bfab3d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

day04/leetcode2665.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 2665. Counter II
2+
// URL -> https://leetcode.com/problems/counter-ii/
3+
4+
/**
5+
* @param {integer} init
6+
* @return { increment: Function, decrement: Function, reset: Function }
7+
*/
8+
var createCounter = function (init) {
9+
var preset = init;
10+
11+
return {
12+
increment: function () {
13+
return ++init;
14+
},
15+
decrement: function () {
16+
return --init;
17+
},
18+
reset: function () {
19+
return init = preset
20+
}
21+
}
22+
};
23+
24+
/**
25+
* const counter = createCounter(5)
26+
* counter.increment(); // 6
27+
* counter.reset(); // 5
28+
* counter.decrement(); // 4
29+
*/

0 commit comments

Comments
 (0)