limit method

int limit(
  1. int min,
  2. int max
)

Restrict value from min to max.

Implementation

int limit(int min, int max) {
  if (this < min) {
    return min;
  }
  if (this > max) {
    return max;
  }
  return this;
}