您好,我有很多玩家,想让第一个满足我两个条件之一的玩家,但是我不确定该怎么做。
首先,我得到玩家的价值(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%或更少
最佳答案
查看find函数的文档,该文档详细介绍了该用例。这是您想要获得预期结果的行。
const matchedPlayer = this.players.find((playerTwo) => playerTwo.mmr > condition || playerTwo.mmr > condition2);