summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cards.json12
-rw-r--r--script.js21
-rw-r--r--script.js.bak92
3 files changed, 21 insertions, 104 deletions
diff --git a/cards.json b/cards.json
deleted file mode 100644
index 8c3bd15..0000000
--- a/cards.json
+++ /dev/null
@@ -1,12 +0,0 @@
-[
- {
- "front": "This is the front page!",
- "back": "This is the back page!",
- "scheduled": "2025-07-17T00:00:00.000Z"
- },
- {
- "front": "Another front page",
- "back": "Another back page",
- "scheduled": "2025-07-20T00:00:00.000Z"
- }
-]
diff --git a/script.js b/script.js
index d7f3890..a0ee7c7 100644
--- a/script.js
+++ b/script.js
@@ -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]);
diff --git a/script.js.bak b/script.js.bak
deleted file mode 100644
index e9b9378..0000000
--- a/script.js.bak
+++ /dev/null
@@ -1,92 +0,0 @@
-// Define a list of objects with "front" and "back" HTML content
-const pages = [
- { front: "This is the front page!", back: "This is the back page!" },
- { front: "Another front page", back: "Another back page" }
-];
-
-// Select the first page from the list
-let currentPage = pages[0];
-let showFront = true;
-
-// Replace the page with the front HTML initially
-document.body.innerHTML = currentPage.front;
-
-// Add an event listener for the spacebar press
-window.addEventListener('keydown', (event) => {
- if (event.code === 'Space') {
- // Toggle between front and back content
- if (showFront) {
- document.body.innerHTML = currentPage.back;
- } else {
- document.body.innerHTML = currentPage.front;
- }
- showFront = !showFront;
- }
-});
-
-// Constants: W as an array of f64 values
-const W = [
- 0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 0.0046, 1.54575, 0.1192,
- 1.01925, 1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655, 0.6621
-];
-
-// Grade enum representation
-const Grade = {
- Forgot: 1.0,
- Hard: 2.0,
- Good: 3.0,
- Easy: 4.0
-};
-
-// Helper to convert Grade to f64 (as in From<Grade> for f64)
-function gradeToNumber(g) {
- return Grade[g];
-}
-
-// Constants
-const F = 19.0 / 81.0;
-const C = -0.5;
-
-// retrievability(t: T, s: S) -> R
-function retrievability(t, s) {
- return Math.pow(1.0 + F * (t / s), C);
-}
-
-// interval(r_d: R, s: S) -> T
-function interval(rD, s) {
- return (s / F) * (Math.pow(rD, 1.0 / C) - 1.0);
-}
-
-// s_0(g: Grade) -> S
-function s0(g) {
- switch (g) {
- case Grade.Forgot: return W[0];
- case Grade.Hard: return W[1];
- case Grade.Good: return W[2];
- case Grade.Easy: return W[3];
- default: throw new Error("Invalid grade");
- }
-}
-
-// s_success(d: D, s: S, r: R, g: Grade) -> S
-function sSuccess(d, s, r, g) {
- const tD = 11.0 - d;
- const tS = Math.pow(s, -W[9]);
- const tR = Math.exp(W[10] * (1.0 - r)) - 1.0;
- const h = (g === Grade.Hard) ? W[15] : 1.0;
- const b = (g === Grade.Easy) ? W[16] : 1.0;
- const c = Math.exp(W[8]);
- const alpha = 1.0 + tD * tS * tR * h * b * c;
- return s * alpha;
-}
-
-// s_fail(d: D, s: S, r: R) => number
-function sFail(d, s, r) {
- return Math.exp(W[8]) - 1.0;
-}
-
-// Main function
-function main() {
- // All functions
-}
-