Trace Logs at a Two-Second Cadence
Problem statement
For this exercise, start a virtual periodic logger at time 0 milliseconds and return its output events through durationMs.
- The first event occurs at
2000ms, then one event occurs every2000ms. - Include an event exactly at the supplied horizon, but none after it. There is no time-zero event.
- Every event carries the supplied
messageunchanged.
Return events in increasing time order as [timestamp, message] rows. The timestamp is base-10 millisecond text with no leading zeros. Use virtual time and return the events immediately.
The source reports the two-second cadence, but no message, start/stop controls, horizon or interface. Those are the stated practice conventions; this function models output events rather than implementing a real browser timer.
Function
tracePeriodicLogs(durationMs: int, message: String) → String[][]Examples
Example 1
durationMs = 5500message = "tick"return = [["2000","tick"],["4000","tick"]]Events occur at 2000 and 4000 ms; the next event at 6000 ms is beyond the horizon.
Example 2
durationMs = 1999message = "ready"return = []The first event is at 2000 ms, so this horizon contains no event.
Constraints
0 <= durationMs <= 1000000.1 <= message.length <= 100.- Every message character is printable ASCII, with a code from
32through126.