I want to limit a number between two values, I know that in PHP you can do this:
$number = min(max(intval($number), 1), 20); // this will make $number 1 if i
Related: What's the most elegant way to cap a number to a segment?:
Update for ECMAScript 2017: Math.clamp(x, lower, upper) But note that as of today, it's a Stage 1 proposal. Until it gets widely supported, you can use a polyfill.
Update for ECMAScript 2017:
Math.clamp(x, lower, upper)
But note that as of today, it's a Stage 1 proposal. Until it gets widely supported, you can use a polyfill.