1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-11 18:31:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

批量更新数据

This commit is contained in:
2025-01-09 20:29:41 +08:00
parent 04ecea043d
commit 48cdd06c2b
5053 changed files with 156164 additions and 135322 deletions

View File

@@ -1,6 +1,12 @@
<p>现给定一个函数 <code>fn</code>,一个参数数组 <code>args</code> 和一个时间间隔 <code>t</code>,返回一个取消函数 <code>cancelFn</code></p>
<p>函数 <code>fn</code> 应该立即使用 <code>args</code> 调用,并且在每个 <code>t</code> 毫秒内再次调用,直到调用 <code>cancelFn</code></p>
<p>在经过 <code>cancelTimeMs</code> 毫秒的延迟后,将调用返回的取消函数 <code>cancelFn</code></p>
<pre>
setTimeout(cancelFn, cancelTimeMs)
</pre>
<p>函数 <code>fn</code> 应立即使用参数 <code>args</code> 调用,然后每隔 <code>t</code> 毫秒调用一次,直到在 <code>cancelTimeMs</code> 毫秒时调用 <code>cancelFn</code></p>
<p>&nbsp;</p>
@@ -18,23 +24,9 @@
{"time": 175, "returned": 8}
]
<strong>解释:</strong>
const result = []
const fn = (x) =&gt; x * 2
const args = [4], t = 35, cancelT = 190
const start = performance.now()
const log = (...argsArr) =&gt; {
const diff = Math.floor(performance.now() - start)
result.push({"time": diff, "returned": fn(...argsArr)})
}
const cancel = cancellable(log, [4], 35);
setTimeout(cancel, 190);
setTimeout(() =&gt; {
console.log(result) // Output
}, cancelT + t + 15)
const cancelTimeMs = 190;
const cancelFn = cancellable((x) =&gt; x * 2, [4], 35);
setTimeout(cancelFn, cancelTimeMs);
每隔 35ms调用 fn(4)。直到 t=190ms然后取消。
第一次调用 fn 是在 0ms。fn(4) 返回 8。
@@ -60,8 +52,9 @@ setTimeout(() =&gt; {
{"time": 150, "returned": 10}
]
<strong>解释:</strong>
const cancel = cancellable((x1, x2) =&gt; (x1 * x2), [2, 5], 30);
setTimeout(cancel, 165);
const cancelTimeMs = 165;
const cancelFn = cancellable((x1, x2) =&gt; (x1 * x2), [2, 5], 30)
setTimeout(cancelFn, cancelTimeMs)
每隔 30ms调用 fn(2, 5)。直到 t=165ms然后取消。
第一次调用 fn 是在 0ms
@@ -85,8 +78,9 @@ setTimeout(cancel, 165);
{"time": 150, "returned": 9}
]
<b>解释:</b>
const cancel = cancellable((x1, x2, x3) =&gt; (x1 + x2 + x3), [5, 1, 3], 50);
setTimeout(cancel, cancelT);
const cancelTimeMs = 180;
const cancelFn = cancellable((x1, x2, x3) =&gt; (x1 + x2 + x3), [5, 1, 3], 50)
setTimeout(cancelFn, cancelTimeMs)
每隔 50ms调用 fn(5, 1, 3)。直到 t=180ms然后取消。
第一次调用 fn 是在 0ms