update matching pairs review
This commit is contained in:
parent
5778ebb4a8
commit
524a5280cd
|
|
@ -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],
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user