From edec40fb85f6ca738dd0807fe339b81f4b0880fd Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Wed, 3 Jan 2024 13:02:40 -0500 Subject: 2665 --- 2665/main.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2665/main.js (limited to '2665') 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 + */ -- cgit v1.2.3