MediumPro challengeJavaScriptTypeScript

useDebounce Hook

ReactHooksAsync

Implement a simulated useDebounce returning a debounced setter.

solve(delay, ops) with simulated time. Each op is { time, value }.
The debounced state updates only when no new value comes within delay ms.

Return the final committed values in chronological order.

Sample tests

Test #1a debounced out by b; b commits (gap > 100); c commits (last)
Input: [100,[{"time":0,"value":"a"},{"time":50,"value":"b"},{"time":200,"value":"c"}]]
Output: ["b","c"]
Test #2Single op commits
Input: [100,[{"time":0,"value":"x"}]]
Output: ["x"]
Test #3All within delay → only last commits
Input: [100,[{"time":0,"value":"a"},{"time":50,"value":"b"},{"time":80,"value":"c"}]]
Output: ["c"]
Test #4All gaps >= delay → all commit
Input: [50,[{"time":0,"value":"a"},{"time":100,"value":"b"},{"time":200,"value":"c"}]]
Output: ["a","b","c"]
Test #5No ops
Input: [100,[]]
Output: []