Ch5 gxd

This is a candidate for the ternary operator, so:
    val = val < min ? min : val;
Although the way you've done it is probably better in this case tbh