schema
schema copied to clipboard
i cant shuffle MapSchema
hello dear frineds im trying to shuffle MapSchema but it automaticly sorting list by key here is my code:
let shuffleKeys = []; this.players.forEach((player, key) => { shuffleKeys.push(key); }); shuffleKeys = H.shuffle(shuffleKeys); // here shuffled int array succesfully
let shuffledPlayers = new MapSchema(); for (let i = 0; i < shuffleKeys.length; i++) { shuffledPlayers.set("" + shuffleKeys[i], this.players.get("" + shuffleKeys[i])); }
this.players = shuffledPlayers;
Maps aren't really supposed to be ordered. Javascript maps do maintain order, at least in newer versions, but that is dangerous behavior to rely on. Use an array to maintain order.