我有一个集合,其中我必须仅使用 javascript 来使用聚合。我已经使用 Lodash 库尝试过一些事情,但没有成功。如果你能指导我以某种方式对集合进行分组,”我认为这应该可以解决。
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
}
]
我期望像下面这样的东西,
result = [{"DESCRIPTOR": "HAPPY", "TOTAL_SCORE":3}, {"DESCRIPTOR": "SAD", "TOTAL_SCORE":4}]
你能帮我只用 JavaScript 编写这段代码吗? 谢谢
人到中年有点甜
凤凰求蛊
相关分类