clamp static method

num clamp(
  1. num x,
  2. num low,
  3. num high
)

Restrict x to the range low, high.

Implementation

static num clamp(num x, num low, num high) =>
    x < low ? low : (x > high ? high : x);