Spaced Repetition Learning: Building LearnLoom with Realm DB and Expo
How to implement the SuperMemo SM-2 spaced repetition algorithm in a React Native flashcard app using Realm DB for offline-first high-speed data access.
Spaced Repetition Learning: Building LearnLoom with Realm DB and Expo
Students who use spaced repetition retain 90% of material vs 20% with traditional study. Here is how we implemented SM-2 in a mobile app.
1. The SM-2 Algorithm
Each card has an ease factor and interval. After each review, the algorithm adjusts when the card should appear next:
typescriptfunction calculateNextReview(card: Card, quality: number) { let { easeFactor, interval, repetitions } = card; if (quality >= 3) { interval = repetitions === 0 ? 1 : repetitions === 1 ? 6 : Math.round(interval * easeFactor); repetitions++; } else { repetitions = 0; interval = 1; } easeFactor = Math.max(1.3, easeFactor + (0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02))); return { ...card, easeFactor, interval, repetitions, nextReview: addDays(new Date(), interval) }; }
2. Why Realm DB
Realm DB offers zero-copy reads, meaning flashcard data loads instantly without serialization overhead — critical for decks with 10,000+ cards.
3. Rich Card Content
Cards support markdown, LaTeX formulas, and embedded images, making them suitable for medical and engineering students.
Summary
Combining proven learning science with fast local databases creates a study app that genuinely improves long-term knowledge retention.