Exercise · From a file to a project · lesson 9 of 10
Exercise: fix it from the test report
Clamp(x, lo, hi int) int must return x clamped to the range from lo to hi: lo when x is below lo, hi when x is above hi, otherwise x itself. It has a bug. Run the tests, find the subtest with a --- FAIL line in the report, and fix the function.
Clamp(5, 0, 10)→5Clamp(-3, 0, 10)→0Clamp(15, 0, 10)→10
Constraints: lo ≤ hi, and lo may equal hi; every number is from -1000000 to 1000000.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.