I am facing a challenge with my collection as I need to perform aggregation using only JavaScript. I have attempted various approaches utilizing the Lodash library but unfortunately, I have not been successful. If you could provide me with some guidance on how to group a collection, I believe that would solve my issue.
var sample = [
{
"DESCRIPTOR": "HAPPY",
"DESCRIPTOR_ID": 400001,
"QUESTION_ID": "A_QUES_1",
"CHOICE": "A",
"SCORE": 1,
"__v": 0
},
{
"DESCRIPTOR": "HAPPY",
"DESCRIPTOR_ID": 400001,
"QUESTION_ID": "A_QUES_2",
"CHOICE": "B",
"SCORE": 2,
"__v": 0
},
{
"DESCRIPTOR": "SAD",
"DESCRIPTOR_ID": 400002,
"QUESTION_ID": "B_QUES_1",
"CHOICE": "A",
"SCORE": 2,
"__v": 0
},
{
"DESCRIPTOR": "SAD",
"DESCRIPTOR_ID": 400002,
"QUESTION_ID": "B_QUES_2",
"CHOICE": "B",
"SCORE": 2,
"__v": 0
}
]
I am looking for an outcome similar to the following:
result = [{"DESCRIPTOR": "HAPPY", "TOTAL_SCORE":3}, {"DESCRIPTOR": "SAD", "TOTAL_SCORE":4}]
I require assistance in writing this scripting code solely in JavaScript. Thank you.