fixed "first letter" clue edge cases

This commit is contained in:
George Powell
2026-02-02 01:27:12 -05:00
parent d797b980ea
commit f7ec0742e1
3 changed files with 56 additions and 14 deletions

View File

@@ -82,6 +82,11 @@
return !!(b1 && b2 && Math.abs(b1.order - b2.order) === 1);
}
function getFirstLetter(bookName: string): string {
const match = bookName.match(/[a-zA-Z]/);
return match ? match[0] : bookName[0];
}
function submitGuess(bookId: string) {
if (guesses.some((g) => g.book.id === bookId)) return;
@@ -98,15 +103,19 @@
// Special case: if correct book is in the Epistles + starts with "1",
// any guess starting with "1" counts as first letter match
const correctIsEpistlesWithNumber =
correctBook.section === "Pauline Epistles" &&
(correctBook.section === "Pauline Epistles" ||
correctBook.section === "General Epistles") &&
correctBook.name[0] === "1";
const guessStartsWithNumber = book.name[0] === "1";
const guessIsEpistlesWithNumber =
(book.section === "Pauline Epistles" ||
book.section === "General Epistles") &&
book.name[0] === "1";
const firstLetterMatch =
correctIsEpistlesWithNumber && guessStartsWithNumber
correctIsEpistlesWithNumber && guessIsEpistlesWithNumber
? true
: book.name[0].toUpperCase() ===
correctBook.name[0].toUpperCase();
: getFirstLetter(book.name).toUpperCase() ===
getFirstLetter(correctBook.name).toUpperCase();
console.log(
`Guess: ${book.name} (order ${book.order}), Correct: ${correctBook.name} (order ${correctBook.order}), Adjacent: ${adjacent}`,
@@ -206,15 +215,19 @@
// Apply same first letter logic as in submitGuess
const correctIsEpistlesWithNumber =
correctBook.section === "Pauline Epistles" &&
(correctBook.section === "Pauline Epistles" ||
correctBook.section === "General Epistles") &&
correctBook.name[0] === "1";
const guessStartsWithNumber = book.name[0] === "1";
const guessIsEpistlesWithNumber =
(book.section === "Pauline Epistles" ||
book.section === "General Epistles") &&
book.name[0] === "1";
const firstLetterMatch =
correctIsEpistlesWithNumber && guessStartsWithNumber
correctIsEpistlesWithNumber && guessIsEpistlesWithNumber
? true
: book.name[0].toUpperCase() ===
correctBook.name[0].toUpperCase();
: getFirstLetter(book.name).toUpperCase() ===
getFirstLetter(correctBook.name).toUpperCase();
return {
book,