programming-examples/js/Math/Limit a value inside a certain range.js
2019-11-15 12:59:38 +01:00

7 lines
221 B
JavaScript

function value_limit(val, min, max) {
return val < min ? min : (val > max ? max : val);
}
console.log(value_limit(7, 1, 12));
console.log(value_limit(-7, 0, 12));
console.log(value_limit(15, 0, 12));