Skip to content

Commit

Permalink
Spaced repetitioin interval should reset to 0 if review session has b…
Browse files Browse the repository at this point in the history
…een interrupted
  • Loading branch information
kubk committed Nov 8, 2023
1 parent 1c05ec2 commit a765d56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions functions/services/review-card.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,22 @@ test("hit yes all the time", () => {
3600 * 24 * 1000 * 15.625,
]);
});

test("forgetting resets interval", () => {
const date = DateTime.fromSQL("2021-05-20 10:00:00");

const { interval: newInterval1 } = reviewCard(date, 0.4, "correct");
expect(newInterval1).toBe(1);

const { interval: newInterval2 } = reviewCard(date, 1, "wrong");
expect(newInterval2).toBe(0);

const { interval: newInterval3 } = reviewCard(date, 0, "wrong");
expect(newInterval3).toBe(0);

const { interval: newInterval4 } = reviewCard(date, 0, "correct");
expect(newInterval4).toBe(0.4);

const { interval: newInterval5 } = reviewCard(date, 0.4, "correct");
expect(newInterval5).toBe(1);
});
5 changes: 4 additions & 1 deletion functions/services/review-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ export const reviewCard = (
const easeFactor = 2.5;

if (reviewOutcome === "correct") {
if (interval === 0) {
interval = 0.16;
}
interval *= easeFactor;
} else if (reviewOutcome === "wrong") {
interval = 0.4;
interval = 0;
}

const nextReviewDate = now.plus({ day: interval });
Expand Down

0 comments on commit a765d56

Please sign in to comment.