massi-world-scratch

a slew of pages that need no compilation
Log | Files | Refs

main.ts (798B)


      1 const NOTES = ["A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"];
      2 
      3 const QUALITIES = ["", "-", "°", "+"];
      4 
      5 const POSSIBILITIES = NOTES.reduce<string[]>((accum, note) => {
      6   return [...accum, ...QUALITIES.map((q) => note + q)];
      7 }, []);
      8 
      9 const bag = new Array(POSSIBILITIES.length).fill(0).map((_, i) => i);
     10 
     11 let result: string[] = [];
     12 while (bag.length > 0) {
     13   const bagIdx = Math.floor(Math.random() * bag.length);
     14   const possibilitiesIdx = bag[bagIdx];
     15   result.push(POSSIBILITIES[possibilitiesIdx]);
     16   bag.splice(bagIdx, 1);
     17 }
     18 
     19 document.addEventListener("DOMContentLoaded", () => {
     20   document.getElementById("chart")!.innerHTML = result
     21     .map((note) => `<code>${note}</code>`)
     22     .join("");
     23 });
     24 
     25 // the other mode would be 1-7 in a given KEY, starting at a given INVERSION.