Value inside range
Input
clamp(5, 1, 10)
Output
5
5 is between 1 and 10, so clamp returns 5.
Full lesson preview
Constrain a value to lie within a specified inclusive range [low, high].
Problem statement
Task
Examples
Input
clamp(5, 1, 10)
Output
5
5 is between 1 and 10, so clamp returns 5.
Input format
Output format
Constraints
Samples
Input
clamp(-3, 0, 7)
Output
0
Value -3 is below low (0), so return 0.