aboutsummaryrefslogtreecommitdiffstats
path: root/2665
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-03 18:02:40 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-03 18:02:40 +0000
commitedec40fb85f6ca738dd0807fe339b81f4b0880fd (patch)
treea3ce90624279f235ee97e3689817632d4085715a /2665
parentupdate (diff)
downloadleetcode-edec40fb85f6ca738dd0807fe339b81f4b0880fd.tar.gz
leetcode-edec40fb85f6ca738dd0807fe339b81f4b0880fd.zip
2665
Diffstat (limited to '2665')
-rw-r--r--2665/main.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/2665/main.js b/2665/main.js
new file mode 100644
index 0000000..e52b085
--- /dev/null
+++ b/2665/main.js
@@ -0,0 +1,32 @@
+#!/usr/bin/env node
+"use strict";
+
+/**
+ * @param {integer} init
+ * @return { increment: Function, decrement: Function, reset: Function }
+ */
+var createCounter = function (init) {
+ var count = init;
+ var object = {
+ increment: function () {
+ count++;
+ return count;
+ },
+ decrement: function () {
+ count--;
+ return count;
+ },
+ reset: function () {
+ count = init;
+ return count;
+ },
+ };
+ return object;
+};
+
+/**
+ * const counter = createCounter(5)
+ * counter.increment(); // 6
+ * counter.reset(); // 5
+ * counter.decrement(); // 4
+ */