clamp function

int clamp(
  1. int x,
  2. int y
)

Returns the closest number to x int the range 0, y.

Implementation

int clamp(int x, int y) => x < 0
    ? 0
    : x > y
        ? y
        : x;