+ 7

JavaScript: How can I assign a variable to a range?

17th May 2017, 7:59 AM
Iwan
Iwan - avatar
6 Antworten
+ 5
function getvalinRange(n,max,min){ return Math.max(Math.min(n, max), min); } // n is the number // max = maximum in range // min = minimum in range
17th May 2017, 8:59 AM
MR Programmer
MR Programmer - avatar
+ 3
do you want a value between maximum​ and minimum
17th May 2017, 8:49 AM
MR Programmer
MR Programmer - avatar
+ 3
Jip
17th May 2017, 8:51 AM
Iwan
Iwan - avatar
+ 1
I know this is late, but the answer you picked (converting the number to one within: minimum ≤ value ≤ maximum) is called clamping the number.
7th Aug 2017, 9:52 PM
Katie (Ctrl-Alt-Cuteness)
Katie (Ctrl-Alt-Cuteness) - avatar