summaryrefslogtreecommitdiff
path: root/notes.js
diff options
context:
space:
mode:
authorSkladnayazebra <skladnayazebra@gmail.com>2026-07-09 16:51:10 +0200
committerSkladnayazebra <skladnayazebra@gmail.com>2026-07-09 16:51:10 +0200
commitd80a2aac1aa7be216dc01437f85b281a64e09687 (patch)
treed5db54663101c6bbea958926918ec91beb62df77 /notes.js
parent018e25e9c5087ee9442945320e37bf54777ad034 (diff)
add notes.js
Diffstat (limited to 'notes.js')
-rw-r--r--notes.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/notes.js b/notes.js
new file mode 100644
index 0000000..b80188c
--- /dev/null
+++ b/notes.js
@@ -0,0 +1,57 @@
+import { createInterface } from 'node:readline/promises';
+
+const noteList = [
+ ["do", "tidi"],
+ ["dodi", "rebe"],
+ ["re"],
+ ["redi", "mibe"],
+ ["mi", "fabe"],
+ ["fa", "midi"],
+ ["fadi", "sobe"],
+ ["so"],
+ ["sodi", "labe"],
+ ["la"],
+ ["ladi", "tibe"],
+ ["ti", "dobe"],
+];
+
+const MAX_INTERVAL = 4;
+
+const randomIndex = (array) => Math.floor(Math.random() * array.length);
+const randomElement = (array) => array[randomIndex(array)];
+
+const readline = createInterface({
+ input: process.stdin,
+ output: process.stdout,
+});
+
+const makeTest = async () => {
+ const startingNoteIndex = randomIndex(noteList);
+ // random number between -$MAX_INTERVAL --- +$MAX_INTERVAL
+ const getInterval = () => Math.round((Math.random() * MAX_INTERVAL * 2) - MAX_INTERVAL);
+ const interval = getInterval()
+ const displayInterval = interval > 0 ? `+${interval}`: interval;
+ const displayStartingNote = randomElement(noteList[startingNoteIndex])
+ // 11 + 4 should yield 3
+ const targetIndex = (startingNoteIndex + interval) % noteList.length
+ const acceptedAnswers = noteList.at(targetIndex);
+
+ performance.mark('start')
+ const response = await readline.question(`${displayStartingNote} ${displayInterval} `)
+ try {
+ if (acceptedAnswers.includes(response)) {
+ performance.mark('end')
+ const { duration } = performance.measure('time', 'start', 'end')
+ console.log('correct!', `Took ${Math.round(duration)/1000}s`);
+ } else {
+ console.log('wrong! should be:', acceptedAnswers.join(', or '))
+ }
+ } catch (e) {
+ console.log('error!');
+ console.log({ startingNoteIndex, interval, targetIndex })
+ }
+}
+
+while (true) {
+ await makeTest()
+}