1 2 3 4 5 6 7 8 9 10 11 12 13 | 1× 23× | /* * Clamps the input `num` between the `min` and `max` values. * * Examples: * clamp(5, 0, 10) // => 5 * clamp(5, 7, 10) // => 7 * clamp(5, 0, 3) // => 3 */ export function clamp(num, min, max) { return Math.max(min, Math.min(max, num)); } |