Version: v0.6.1 - Beta.  We welcome contributors & feedback.  THanks!

Math.clamp

Math.clamp($n, $min, $max)

Description

Ensure that $n is within the boundary of $min and $max. If outside the boundary, return the nearest boundary ($min or $max).

Math.clamp(5, 1, 10);    //= 5  (within boundary)
Math.clamp(20, 1, 10);   //= 10 (max)
Math.clamp(-20, 1, 10);  //= 1  (min)