-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 60 ms (52.01%), Space: 50.8 MB (97.92%) - LeetHub
- Loading branch information
1 parent
963db26
commit 5d60d73
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @param {integer} init | ||
* @return { increment: Function, decrement: Function, reset: Function } | ||
*/ | ||
var createCounter = function(init) { | ||
let count = init; | ||
|
||
return { | ||
increment() { | ||
count += 1; | ||
return count; | ||
}, | ||
decrement() { | ||
count -= 1; | ||
return count; | ||
}, | ||
reset() { | ||
count = init; | ||
return count; | ||
} | ||
}; | ||
}; | ||
|
||
/** | ||
* const counter = createCounter(5) | ||
* counter.increment(); // 6 | ||
* counter.reset(); // 5 | ||
* counter.decrement(); // 4 | ||
*/ |