summaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2025-07-19 17:49:17 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2025-07-19 17:49:17 -0400
commit6bb3cd1c923fd37ab15501f5bb089c107e5f341c (patch)
tree17cec6e6432d7fe1b954a78cf2e50b21e08e6e4e /script.js
parent13d5d2a8773d8800eb1b5be59db921b11b6661a2 (diff)
Randomize deck ordering
Diffstat (limited to 'script.js')
-rw-r--r--script.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/script.js b/script.js
index d7f3890..a0ee7c7 100644
--- a/script.js
+++ b/script.js
@@ -281,6 +281,26 @@ function checkCards(cards) {
}
}
+function shuffleArray(array) {
+ let currentIndex = array.length;
+ let randomIndex;
+
+ // While there remain elements to shuffle.
+ while (currentIndex !== 0) {
+ // Pick a remaining element.
+ randomIndex = Math.floor(Math.random() * currentIndex);
+ currentIndex--;
+
+ // And swap it with the current element.
+ [array[currentIndex], array[randomIndex]] = [
+ array[randomIndex],
+ array[currentIndex],
+ ];
+ }
+
+ return array;
+}
+
function loadCards(data) {
checkCards(data);
@@ -311,6 +331,7 @@ function loadCards(data) {
window.cards = data.filter((card) => {
return (new Date(card.scheduled)) <= today;
});
+ shuffleArray(window.cards);
loadCard(window.cards[0]);