From b4c46277fb0c54c766704246c373e2321dba5b9f Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sun, 30 Jan 2022 14:40:24 +0000 Subject: [PATCH] Add ability to ignore capitals during tests --- functions/index.js | 22 +++++++++++++++------- src/ClassicTestStart.js | 9 +++++++++ src/LivesTestStart.js | 9 +++++++++ src/LoggedInHome.js | 12 ++++++++++++ src/Progress.js | 1 + src/SetPage.js | 12 ++++++++++++ 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/functions/index.js b/functions/index.js index bd4dbea..8dfff8c 100644 --- a/functions/index.js +++ b/functions/index.js @@ -140,10 +140,11 @@ exports.getGroupMembers = functions.https.onCall((data, context) => { /** * Creates new progress document. * @param {object} data The data passed to the function. + * @param {boolean} data.ignoreCaps Whether capitalisation of answers should matter during the test. + * @param {boolean} data.limit The maximum number of lives/questions for the test. + * @param {boolean} data.mode The mode to be tested in. Valid options are "questions" and "lives". * @param {array} data.sets An array of IDs of the desired sets. * @param {boolean} data.switch_language Whether or not the languages should be reversed. - * @param {boolean} data.mode The mode to be tested in. Valid options are "questions" and "lives". - * @param {boolean} data.limit The maximum number of lives/questions for the test. * @return {string} The ID of the created progress document. */ exports.createProgress = functions.https.onCall((data, context) => { @@ -237,6 +238,7 @@ exports.createProgress = functions.https.onCall((data, context) => { setIds: setIds, set_titles: setIds.map((setId) => setTitlesDict[setId]), typo: false, + ignoreCaps: data.ignoreCaps, } return { @@ -462,9 +464,14 @@ function arraysHaveSameMembers(arr1, arr2) { * @param {string} item The term/definition to remove the characters that should be ignored from. * @return {string} The original string with the unwanted characters removed. */ -function cleanseVocabString(item) { +function cleanseVocabString(item, ignoreCaps=false) { const chars = /[\p{P}\p{S} ]+/ug; - return item.replace(chars, ""); + const cleansed = item.replace(chars, ""); + if (ignoreCaps) { + return cleansed.toLowerCase(); + } else { + return cleansed; + } } /** @@ -541,15 +548,16 @@ exports.processAnswer = functions.https.onCall((data, context) => { if (index !== -1) { cleansedDoneSplitCorrectAnswers.push( cleanseVocabString( - notDoneSplitCorrectAnswers.splice(index, 1)[0] + notDoneSplitCorrectAnswers.splice(index, 1)[0], + docData.ignoreCaps ) ); } }); - const cleansedNotDoneSplitCorrectAnswers = notDoneSplitCorrectAnswers.map((answer) => cleanseVocabString(answer)); + const cleansedNotDoneSplitCorrectAnswers = notDoneSplitCorrectAnswers.map((answer) => cleanseVocabString(answer, docData.ignoreCaps)); const cleansedSplitCorrectAnswers = cleansedNotDoneSplitCorrectAnswers.concat(cleansedDoneSplitCorrectAnswers); - const cleansedInputAnswer = cleanseVocabString(inputAnswer); + const cleansedInputAnswer = cleanseVocabString(inputAnswer, docData.ignoreCaps); let isCorrectAnswer = false; let correctAnswerIndex; diff --git a/src/ClassicTestStart.js b/src/ClassicTestStart.js index 41172f7..70d2abc 100644 --- a/src/ClassicTestStart.js +++ b/src/ClassicTestStart.js @@ -61,6 +61,15 @@ export default function ClassicTestStart(props) { Switch language + +