0

We are trying to add a second calculation that meets to the same min, max range of the math in JavaScript.

function AllowableRange(Item) {
    ...
    var range1 = // some calculation
    var range2 = // another calculation

    return Math.min(800, Math.max(0, range1));

How can I add range2 in the return statement for the same math min - max range?

NewTech Lover
  • 1,185
  • 4
  • 20
  • 44
  • What is the expected result in an example , please ? – TheoWckr Apr 04 '20 at 09:47
  • when range1 calculation is done it shows that value withing the min and max based on the calculation. The second range2 is a different calculation that needs to be in the same math min-max range. So how can 2nd range2 based calculation display the related value as range1 does with above return? – NewTech Lover Apr 04 '20 at 09:50
  • So both range1 and range2 calculations should show the result based on the same min and max values in the return. – NewTech Lover Apr 04 '20 at 09:54
  • Please take a look at this [Return multiple values in JavaScript?](https://stackoverflow.com/questions/2917175/return-multiple-values-in-javascript) – Shlang Apr 04 '20 at 11:42

1 Answers1

0

I'm not sure to understand the 'show the result ' part.

Well i guess you make first the calculation you made and stock it in a variable

var min1 = Math.min(800, Math.max(0, range1));

Then the second

var min2 = Math.min(800, Math.max(0, range2));

and then return the expected result

return Math.min(min1,min2)

TheoWckr
  • 209
  • 1
  • 4
  • range1 and range2 are independent of each other. The only point is that they both should show the value between those mins and max. They are completely separate but should from the same function. I tried something like this but it didn't work. return Math.min(800, Math.max(0, range1, range2)); – NewTech Lover Apr 04 '20 at 10:04