function scale(fullMode) {
let { tonic, mode } = fullMode;
while (mode < 0) mode += 7;
while (tonic < 0) tonic += 12;
mode = mode % 7;
tonic = tonic % 12;
tonic = tonicName[tonic];
mode = modeTranspositions[mode];
const baseNote = tonic[0];
const allNotes = "CDEFGABCDEFGAB";
const allIntervals = [2, 2, 1, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1];
const ix = allNotes.indexOf(baseNote);
const notes = allNotes.slice(ix, ix+7);
const noteIntervals = [0, ...allIntervals.slice(ix, ix + 7)];
const modeIntervals = [0, ...allIntervals.slice(mode, mode + 7)];
const result = [];
let runningAccidental = isFlat(tonic) ? -1 : isSharp(tonic) ? 1 : 0;
for (let i = 0; i < 7; ++i) {
runningAccidental += modeIntervals[i] - noteIntervals[i];
const accidental =
(runningAccidental === 0 ? ""
:runningAccidental < 0 ? "♭".repeat(Math.abs(runningAccidental))
:"♯".repeat(runningAccidental));
result.push((notes[i] + accidental).replaceAll("♯♯", "𝄪"));
}
return result;
}