a4b66954bd
Hop-State: A_06FNNZKG8MKNEJA6QXQ1ZER Hop-Proposal: R_06FNNZJMKS1Z9RBS9ADD3ER Hop-Task: T_06FNNXTJEGA5TEAZ2GA55X0 Hop-Attempt: AT_06FNNXTJEHPH9SQPGKC0P9G
19 lines
566 B
TypeScript
19 lines
566 B
TypeScript
export type RepeatMode = "off" | "all" | "one";
|
|
|
|
export function nextRepeatMode(mode: RepeatMode): RepeatMode {
|
|
if (mode === "off") return "all";
|
|
if (mode === "all") return "one";
|
|
return "off";
|
|
}
|
|
|
|
export function shuffleTracks<T>(items: readonly T[], random: () => number = Math.random): T[] {
|
|
const shuffled = [...items];
|
|
|
|
for (let index = shuffled.length - 1; index > 0; index -= 1) {
|
|
const swapIndex = Math.floor(random() * (index + 1));
|
|
[shuffled[index], shuffled[swapIndex]] = [shuffled[swapIndex], shuffled[index]];
|
|
}
|
|
|
|
return shuffled;
|
|
}
|