leetcode 30 days js challenge
Easy
Write a function createCounter
. It should accept an initial integer init
. It should return an object with three functions.
The three functions are:
increment()
increases the current value by 1 and then returns it.decrement()
reduces the current value by 1 and then returns it.reset()
sets the current value to init
and then returns it.Example 1:
Example 2:
Constraints:
-1000 <= init <= 1000
total calls not to exceed 1000
SheepSun, May 7, 2023