From 524a5280cdc35e381d0b5c69e3c0783aa3084573 Mon Sep 17 00:00:00 2001 From: Dimas Atmodjo Date: Thu, 19 Dec 2024 21:40:32 +0700 Subject: [PATCH] update matching pairs review --- .../views/components/MatchingPairsQuestion.jsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/roles/user/review/views/components/MatchingPairsQuestion.jsx b/src/roles/user/review/views/components/MatchingPairsQuestion.jsx index 135a168..c3d957a 100644 --- a/src/roles/user/review/views/components/MatchingPairsQuestion.jsx +++ b/src/roles/user/review/views/components/MatchingPairsQuestion.jsx @@ -22,6 +22,17 @@ function stringToArray(str) { return str.split(', '); } +function extractAnswer(input) { + const lines = input.split('|'); + + const descriptions = lines.map(line => { + const parts = line.split('>'); + return parts[1]?.trim(); + }); + + return descriptions; +} + const MatchingPairsQuestion = ({ question, studentAnswer, index }) => { const savedAnswer = studentAnswer !== null ? studentAnswer : null; const [pairs, setPairs] = useState([]); @@ -54,7 +65,12 @@ const MatchingPairsQuestion = ({ question, studentAnswer, index }) => { })); if (savedAnswer !== null) { - const arrSavedAnswer = stringToArray(savedAnswer); + //if use "," as separator + // const arrSavedAnswer = stringToArray(savedAnswer); + + //if use ">" as separator + const arrSavedAnswer = extractAnswer(savedAnswer); + const updatedPairs = initialPairs.map((pair, index) => ({ ...pair, right: arrSavedAnswer[index],