clampTo method

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

Clamps the number between min and max.

Example:

15.clampTo(0, 10); // 10
5.clampTo(0, 10); // 5

Implementation

int clampTo(int min, int max) {
  assert(min <= max, 'min must be less than or equal to max');
  return this < min ? min : (this > max ? max : this);
}