randomise cube, and separate out setup function

This commit is contained in:
Rhiannon Morris 2025-02-16 22:40:33 +01:00
parent 717bae78f5
commit 5e83230768
4 changed files with 39 additions and 27 deletions

View file

@ -1,4 +1,4 @@
function shuffle<A>(subject: A[]): A[] {
export function shuffle<A>(subject: A[]): A[] {
const res = Array.from(subject);
for (let i = 0; i < res.length - 1; ++i) {
@ -38,11 +38,11 @@ function group<A>(subject: A[], keepTogether: A[][]): A[][] {
return res;
}
function groupedShuffle<A>(subject: A[], keepTogether: A[][]): A[] {
export function groupedShuffle<A>(subject: A[], keepTogether: A[][]): A[] {
return shuffle(group(subject, keepTogether)).flat();
}
function shuffleAll() {
export function setup() {
const groups = [group('myno', 'abyss'), group('clip', 'cervine')];
for (const elem of Array.from(document.getElementsByClassName('shuffle'))) {
@ -59,7 +59,3 @@ function shuffleAll() {
return elements.every(x => x) ? elements as HTMLElement[] : [];
}
}
document.addEventListener('DOMContentLoaded', shuffleAll);
export {};