diff options
Diffstat (limited to 'script.js')
| -rw-r--r-- | script.js | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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]); |