Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NaN from missing difficulty of book #2918

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/scripture/book-difficulty-factor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Book } from '@seedcompany/scripture';
import { difficultyOfBook } from './book-difficulty-factor';

test.each([...Book])(`difficultyOfBook is defined: %s`, (book) => {
expect(difficultyOfBook(book)).toBeDefined();
});
9 changes: 5 additions & 4 deletions src/components/scripture/book-difficulty-factor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Book } from '@seedcompany/scripture';
import { BookDifficulty } from './dto';

export const difficultyFactorOfBook = (book: Book): number =>
factorMap[difficultyOfBook(book)];
factorMap[difficultyOfBook(book)] ?? 0;

export const difficultyOfBook = (book: Book) => difficultyMap[book.name];
export const difficultyOfBook = (book: Book): BookDifficulty =>
difficultyMap[book.name];

const factorMap: Record<BookDifficulty, number> = {
Easy: 0.8,
Expand All @@ -13,7 +14,7 @@ const factorMap: Record<BookDifficulty, number> = {
Hardest: 1.5625,
};

const difficultyMap: Record<string, `${BookDifficulty}`> = {
const difficultyMap: Record<string, BookDifficulty> = {
Genesis: 'Normal',
Exodus: 'Normal',
Leviticus: 'Hard',
Expand All @@ -32,7 +33,7 @@ const difficultyMap: Record<string, `${BookDifficulty}`> = {
Nehemiah: 'Normal',
Esther: 'Easy',
Job: 'Hardest',
Psalm: 'Hard',
Psalms: 'Hard',
Proverbs: 'Hard',
Ecclesiastes: 'Hard',
'Song of Solomon': 'Hard',
Expand Down