A resize handler is throttled with both edges, so the layout updates right away and also once more after the user stops dragging. The rules:
wait ms starts.wait ms starts. If nothing was remembered, the cooldown just ends.If a cooldown ends at exactly the time of a call, the cooldown's ending is handled first. Write throttleBothEdges(calls, wait) that returns the times the handler runs. calls is sorted ascending.
Input: calls = [0,50,120,130], wait = 100 Output: [0,100,200]
Runs at 0. 50 is remembered and runs when the cooldown ends at 100, starting a new cooldown to 200. 120 and 130 are remembered and run once at 200.
Input: calls = [0,300], wait = 100 Output: [0,300]
The calls are far apart, so each runs at once.
0 <= calls.length <= 10^50 <= calls[i] <= 10^9, sorted ascending.1 <= wait <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #721 Throttle with a Trailing Call. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.