rework player store and add global player context

This commit is contained in:
jeffvli
2025-11-02 01:09:40 -07:00
parent b35b805a8e
commit 1d4069d4fa
4 changed files with 1484 additions and 1089 deletions
+22
View File
@@ -0,0 +1,22 @@
export function shuffle<T>(array: T[]): T[] {
// Create a copy of the array to avoid mutating the original
const shuffled = [...array];
// Loop through the array from the last element to the first
for (let i = shuffled.length - 1; i > 0; i--) {
// Generate a random index from 0 to i
const j = Math.floor(Math.random() * (i + 1));
// Swap elements at positions i and j
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
export function shuffleInPlace<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}