Currently, I am working on an application that allows users to read articles and take quizzes. Each article is assigned to a unique category with its own _id. Quiz attempts are stored in a separate table that references the articles, which in turn reference the categories.
To analyze quiz attempts, I have created an array of objects by looping through the data:
const userScoreArray = [];
for(let i = 0; i < data[1].length; i++) {
userScoreArray.push({[data[1][i]['dataValues']['article_id']]: data[1][i]['dataValues']['score'] }) // overall
}
This array now contains quiz attempts per category like this:
[
{4: 5},
{4: 1},
{3: 6},
{5: 0}
// {category: score}
]
The challenge now is to extract objects with key "4" from the array, add their values together, and repeat the process for objects with key "5". While a loop might work, it's a bit overwhelming. Any suggestions on a more efficient approach?