代码拉取完成,页面将自动刷新
<p>Write a function <code>createCounter</code>. It should accept an initial integer <code>init</code>. It should return an object with three functions.</p>
<p>The three functions are:</p>
<ul>
<li><code>increment()</code> increases the current value by 1 and then returns it.</li>
<li><code>decrement()</code> reduces the current value by 1 and then returns it.</li>
<li><code>reset()</code> sets the current value to <code>init</code> and then returns it.</li>
</ul>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> init = 5, calls = ["increment","reset","decrement"]
<strong>Output:</strong> [6,5,4]
<strong>Explanation:</strong>
const counter = createCounter(5);
counter.increment(); // 6
counter.reset(); // 5
counter.decrement(); // 4
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> init = 0, calls = ["increment","increment","decrement","reset","reset"]
<strong>Output:</strong> [1,2,1,0,0]
<strong>Explanation:</strong>
const counter = createCounter(0);
counter.increment(); // 1
counter.increment(); // 2
counter.decrement(); // 1
counter.reset(); // 0
counter.reset(); // 0
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-1000 <= init <= 1000</code></li>
<li><code>0 <= calls.length <= 1000</code></li>
<li><code>calls[i]</code> is one of "increment", "decrement" and "reset"</li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。