Ok, I don’t know how to put this in short.
This is my code:
var ratio, input={w:100,h:50};
if(input.w <= input.h) ratio = input.h / input.w;
else ratio = input.w / input.h;
Question:
Is there faster, better, “less code needed” way to calculate ratio ? Than if/else statements.
Thanks!
You can use the ternary conditional operator. Syntax:
In your case:
EDIT:
This isn’t faster than your solution, just faster to write. I would advise against using:
That will compare the numbers twice (once in Math.Max, once in Math.Min) and would be slower.