Prototype: PriorityQueue.add(name,priority) returns increasing numeric IDs starting 1; pop removes highest priority then lowest numeric ID as [id,name] or null. Names may be empty/duplicates; priority any safe integer. IDs never reused.

Final: TaskScheduler.addTask uses same order/IDs. addWorker(workerId,capacity) requires positive integer capacity before duplicate check, preserving original quota. dispatch(ts,workerId,lease) requires positive lease, expires old leases, then returns best Task snapshot or null for unknown/full/no pending. Successful globally increasing lease tokens start 1; failures consume none. complete(ts,taskId,token) returns true only for exact active unexpired lease and marks done. getTask/active also expire first; active returns fresh ID-sorted snapshots. Task keys exactly {id,name,priority,status,worker,expiresAt,token}; assignment fields null for pending/done. All timed calls accept nonnegative nondecreasing integer ts; valid failures advance time, invalid calls preserve it. Expiry is expiresAt<=ts. IDs/tokens accepted by public methods must be safe integers. Worker IDs are strings, including empty.

Every class is exported by name from exercise.mjs. Keep instances independent. Unless explicitly documented otherwise, input values have the stated collection/string types and do not contain null elements. Invalid calls preserve state; validate before mutation. Return fresh mutable snapshots unless stated otherwise.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.