Skip to interview prep
Apexed

5. Refactor for testability: business hours

MediumDebugging & productionDebugging

isOpen decides whether support is open (Monday–Friday, 09:00 until 17:00). It reads the system clock, so its tests are flaky: they pass or fail depending on when they run.

Refactor it to take the day of the week (0 = Sunday … 6 = Saturday) and the hour (0–23) as parameters: isOpen(day, hour). Production code can pass the current time in.

Example 1

Input: isOpen(5, 17)
Output: false

Constraints

  • Fix the bug; keep the function signature

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Refactor for testability: business hours — coding interview practice — Apexed