Created
June 5, 2026 11:49
-
-
Save mosioc/a535e545aa803893d231fb66be4fedb2 to your computer and use it in GitHub Desktop.
5-Box Leitner Spaced Repetition System - G5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // map of box index to the days interval array | |
| const G5_INTERVALS = [1, 2, 5, 9, 14]; | |
| interface Flashcard { | |
| id: string; | |
| word: string; | |
| definition: string; | |
| box: number; // 1 to 5 | |
| nextReviewDate: Date; | |
| } | |
| // execute user response evaluation | |
| function processReview(card: Flashcard, isCorrect: boolean): Flashcard { | |
| const updatedCard = { ...card }; | |
| if (isCorrect) { | |
| // move forward up to box 5 | |
| updatedCard.box = Math.min(card.box + 1, 5); | |
| } else { | |
| // reset to box 1 on failure | |
| updatedCard.box = 1; | |
| } | |
| // calculate next review timestamp | |
| const targetDays = G5_INTERVALS[updatedCard.box - 1]; | |
| const today = new Date(); | |
| today.setDate(today.getDate() + targetDays); | |
| updatedCard.nextReviewDate = today; | |
| return updatedCard; | |
| } |
Author
// sample starting card in box 3
const initialCard: Flashcard = {
id: "vocab-001",
word: "déjà vu",
definition: "the illusion of having previously experienced something",
box: 3,
nextReviewDate: "2026-06-05",
};
// scenario a: user gets it right! card gets promoted to box 4
const promotedCard = reviewCard(initialCard, true);
console.log(promotedCard.box); // output: 4
console.log(promotedCard.nextReviewDate); // output: (today's date + 9 days)
// scenario b: user slips up! card drops all the way back to box 1
const failedCard = reviewCard(initialCard, false);
console.log(failedCard.box); // output: 1
console.log(failedCard.nextReviewDate); // output: (today's date + 1 day)
Author
// sample starting card in box 3
const initialCard: Flashcard = {
id: "vocab-001",
word: "déjà vu",
definition: "the illusion of having previously experienced something",
box: 3,
nextReviewDate: "2026-06-05",
};
// scenario a: user gets it right! card gets promoted to box 4
const promotedCard = reviewCard(initialCard, true);
console.log(promotedCard.box); // output: 4
console.log(promotedCard.nextReviewDate); // output: (today's date + 9 days)
// scenario b: user slips up! card drops all the way back to box 1
const failedCard = reviewCard(initialCard, false);
console.log(failedCard.box); // output: 1
console.log(failedCard.nextReviewDate); // output: (today's date + 1 day)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.