schema icon indicating copy to clipboard operation
schema copied to clipboard

i cant shuffle MapSchema

Open hdev72 opened this issue 2 years ago • 1 comments

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;

hdev72 avatar Jul 08 '22 09:07 hdev72

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.

hunkydoryrepair avatar Jul 12 '23 18:07 hunkydoryrepair