So i have two sets of data:
The first data is the answer key of an exam.
The second data is the answers from students whom are doing the exam.
From those two data, i tried to array.map them both.
const answerKey = [{
id: "bida01",
answerKey: "b",
category: "bida",
nomorSoal: "01",
score: 20
},
{
id: "bida02",
answerKey: "b",
category: "bida",
nomorSoal: "02",
score: 30
}
]
const participants1 = [{
answers: {
bida01: "a",
bida02: "b",
bida03: "c",
},
category: "bida",
firstName: "John",
lastName: "Collins",
school: "Something Junior High",
address: "Somewhere",
email: "[email protected]"
},
{
answers: {
bida01: "b",
bida02: "b",
bida03: "a",
},
category: "bida",
firstName: "Jennifer",
lastName: "Harley",
school: "Somewhere Junior High",
address: "Also somewhere",
email: "[email protected]"
}
]
const answerKeyData = answerKey.map((elem) => {
console.log(elem.id, elem.answerKey, elem.score);
})
const participantData = participants1.map((elem, idx) => {
console.log(elem.answer, elem.firstName, elem.middleName, elem.lastName, elem.school);
});
Now i can see from the result of those console.logs that i can get the values i want to compare. My purpose here is to compare student's answer to the answer keys, and then if they are a match:
return score += elem.score
But how do i access that elem.id, elem.answerKey, elem.score? Should i make a new object (lets say objectAnswerKey) with them? How can i do that?
The same with elem.firstName, elem.middleName, elem.lastName, elem.school, and elem.answer. Should i make a new object (lets say objectAnswer) and then compare objectAnswer and objectAnswerKey?
Or is there a more simple way?