EasyPythonJavaScriptTypeScript

Clamp

MathFunctions

Implement solve(value, min, max) that clamps value to the [min, max]
range — returning min if below it, max if above it, or value otherwise.

Examples

  • solve(5, 0, 10)5
  • solve(-3, 0, 10)0
  • solve(15, 0, 10)10
  • solve(5, 5, 5)5

Sample tests

Test #1Value inside range
Input: [5,0,10]
Output: 5
Test #2Value below min
Input: [-3,0,10]
Output: 0
Test #3Value above max
Input: [15,0,10]
Output: 10
Test #4All three equal
Input: [5,5,5]
Output: 5
Test #5Negative range, value below min
Input: [-100,-50,-10]
Output: -50