[Solved] Fast way to check the biggest variable? [closed]


One way, if you cannot use object, then get max value and then check individual values to variable. Here you will not have very complex condition. Also its better to if...else if...else than multiple if

a = 55;
b = 13;
c = 45;
d = 5;

var max = Math.max(a,b,c,d);
var varName = "";

if(max === a){
  varName = "a";
}
else if(max === b){
  varName = "b";
}
else if(max === c){
  varName = "c";
}
else{
  varName = d;
}

alert(varName);

3

solved Fast way to check the biggest variable? [closed]