您好,我有一个玩家队列,想要获得第一个满足我的两个条件之一的玩家,但我不确定如何做到这一点。首先,我得到一个玩家 (mmr) 的值,并希望从队列中获得一个(只有一个)玩家,该玩家的值或多或少 5%我认为我的情况是获得或多或少 5%: const condition = (5/100)*playerOne.mmr + playerOne.mmr const condition2 = (5/100)*playerOne.mmr - playerOne.mmr我的功能:makeMatch(playerOne) { // make matched players const condition = (5/100)*playerOne.mmr + playerOne.mmr const condition2 = (5/100)*playerOne.mmr - playerOne.mmr const player = playerOne; const matchedPlayer = this.players.find(); // remove matched players from this.players this.removePlayers(matchedPlayers); // return new Match with matched players return new Match(matchedPlayers);}我有疑问,因为我会在我的发现中获得或多或少 5%
2 回答
智慧大石
TA贡献1946条经验 获得超3个赞
你可以尝试这样的事情:
if (player.condition1 > condition1*0.95 && player.condition1 < condition1*1.05) {
// then you keep the player
} else {
// else you remove it from the list
}
另外,我强烈建议您为变量提供更好的标识符。而不是条件1,类似age, height, weight。
添加回答
举报
0/150
提交
取消