aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
+ */