代码拉取完成,页面将自动刷新
<p>Given a function <code>fn</code>, return a new function that is identical to the original function except that it ensures <code>fn</code> is called at most once.</p>
<ul>
<li>The first time the returned function is called, it should return the same result as <code>fn</code>.</li>
<li>Every subsequent time it is called, it should return <code>undefined</code>.</li>
</ul>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]
<strong>Output:</strong> [{"calls":1,"value":6}]
<strong>Explanation:</strong>
const onceFn = once(fn);
onceFn(1, 2, 3); // 6
onceFn(2, 3, 6); // undefined, fn was not called
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]
<strong>Output:</strong> [{"calls":1,"value":140}]
<strong>Explanation:</strong>
const onceFn = once(fn);
onceFn(5, 7, 4); // 140
onceFn(2, 3, 6); // undefined, fn was not called
onceFn(4, 6, 8); // undefined, fn was not called
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>calls</code> is a valid JSON array</li>
<li><code>1 <= calls.length <= 10</code></li>
<li><code>1 <= calls[i].length <= 100</code></li>
<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。