clamp method

num clamp(
  1. num min,
  2. num max
)

Implementation

num clamp(num min, num max) {
  if (this < min) {
    return min;
  } else if (this > max) {
    return max;
  } else {
    return this;
  }
}