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],