problems(js): add “2665. Counter II”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
84885aa0c9
commit
42c87b3aca
1 changed files with 19 additions and 0 deletions
19
problems/counter-ii.js
Normal file
19
problems/counter-ii.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @param {integer} init
|
||||
* @return { increment: Function, decrement: Function, reset: Function }
|
||||
*/
|
||||
var createCounter = function(init) {
|
||||
let n = init;
|
||||
return {
|
||||
increment: () => ++n,
|
||||
decrement: () => --n,
|
||||
reset: () => (n = init),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* const counter = createCounter(5)
|
||||
* counter.increment(); // 6
|
||||
* counter.reset(); // 5
|
||||
* counter.decrement(); // 4
|
||||
*/
|
Loading…
Reference in a new issue