0
Well I have a Queue ( that is a collection of players)
class Queue {
constructor() {
this.players = [];
}
// addPlayers add multiple players into queue
addPlayers(players) {
this.players = this.players.concat(players);
}
// addPlayer adds a single player into queue
addPlayer(player) {
if(!this.players.find(p => p.id == player.id)){
this.players.push(player);
}
}
// removePlayers remove multiple players from queue
removePlayers(players) {
players.forEach(p => {
this.removePlayer(p);
});
}
// removePlayer removes a single player from queue
removePlayer(player) {
this.players = this.players.filter(p => p.id !== player.id)
}
// getPlayers return players that are currently on queue
getPlayers() {
return this.players;
}
searching(id) {
const firstPLayer = this.players.find(p => p.id == id)
const { mmr } = firstPLayer
const secondPlayer = this.players.find((playerTwo) => playerTwo.mmr < (5 / 100) * mmr + mmr && playerTwo.mmr > mmr - ((5 / 100) * mmr) && playerTwo.id != firstPLayer.id);
if(!secondPlayer){
return null;
}
const matchedPlayers = [
firstPLayer,
secondPlayer
]
// remove matched players from this.players
this.removePlayers(matchedPlayers);
// return new Match with matched players
return matchedPlayers;
}
}
and then I need to remove from this list two players ( players ) randomly who obey a condition that has mmr equal or between 5% for more or for less.
Or it takes 2 players who meet this condition
I thought to do this using a filter and dps a Slice(0.2) but in my filter I can’t imagine how I could filter the players that have mmr equal or between 5% more or less I don’t think that’s possible. Could someone help me with this?