mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 20:40:15 +02:00
rework player store and add global player context
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user