HardPro challengeJavaScriptTypeScript

Fiber Work Loop

ReactFiberScheduling

Implement a simplified fiber work loop that processes units of work
cooperatively. Each fiber: { id, work: number }. Process them in order,
yielding to allow priority interrupts.

solve(initial, interrupts) processes initial fibers; after each step
the scheduler checks for new interrupts { atStep, fibers } to add to the
front of the queue. Returns the order fibers completed.

Sample tests

Test #1No interrupts
Input: [[{"id":"a","work":1},{"id":"b","work":1}],[]]
Output: ["a","b"]
Test #2Interrupt at step 0
Input: [[{"id":"a","work":1},{"id":"b","work":1}],[{"atStep":0,"fibers":[{"id":"urgent","work":1}]}]]
Output: ["urgent","a","b"]
Test #3Single fiber
Input: [[{"id":"a","work":1}],[]]
Output: ["a"]
Test #4Interrupt at step 1
Input: [[{"id":"a","work":1},{"id":"b","work":1},{"id":"c","work":1}],[{"atStep":1,"fibers":[{"id":"x","work":1}]}]]
Output: ["a","x","b","c"]
Test #5Empty queue
Input: [[],[]]
Output: []