diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-01-03 18:02:40 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-01-03 18:02:40 +0000 |
commit | edec40fb85f6ca738dd0807fe339b81f4b0880fd (patch) | |
tree | a3ce90624279f235ee97e3689817632d4085715a | |
parent | update (diff) | |
download | leetcode-edec40fb85f6ca738dd0807fe339b81f4b0880fd.tar.gz leetcode-edec40fb85f6ca738dd0807fe339b81f4b0880fd.zip |
2665
-rw-r--r-- | 2665/main.js | 32 |
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 + */ |