We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b2322ee commit 3bfab3dCopy full SHA for 3bfab3d
day04/leetcode2665.js
@@ -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