Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i cant shuffle MapSchema #132

Open
hdev72 opened this issue Jul 8, 2022 · 1 comment
Open

i cant shuffle MapSchema #132

hdev72 opened this issue Jul 8, 2022 · 1 comment

Comments

@hdev72
Copy link

hdev72 commented Jul 8, 2022

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;

@hunkydoryrepair
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants