JSFiddle - React, Tailwind, and code Playground
JavaScript
function biggerThanOther(player1,player2){
if (player1.score > player2.score){
return player1;
}
else if (player2.score > player1.score){
return player2;
}
else{ //scores are equal
if (player1.coeficent > player2.coeficent){
return player1;
}
else if (player2.coeficent > player1.coeficent){
return player2;
}
else{ //coeficents are equal
ratio1 = player1.ratio;
ratio_split = ratio1.split(":");
ratio1 = ratio_split[0]-ratio_split[1];
ratio2 = player2.ratio;
ratio_split = ratio2.split(":");
ratio2 = ratio_split[0]-ratio_split[1];
if (ratio1 > ratio2){
return player1;
}
else if (ratio 2 > ratio 1){
return player2;
}
else{
return "They're equal";
}
}
}
}
var playerA = new Object();
playerA["name"] = "A";
playerA["score"] = 5;
playerA["coeficent"] = 4;
playerA["ratio"] = "5:2";
var playerB = new Object();
playerB["name"] = "B";
playerB["score"] = 5;
playerB["coeficent"] = 4;
playerB["ratio"] = "6:1";
alert(biggerThanOther(playerA,playerB).name);