У меня есть массив таких объектов:
[
{
name: "aaa",
mainName: "bbb",
occurrences: 3,
collectTime: "15-OCT-2018 09:03:02",
status: "unfinished"
},
{
name: "aaa",
mainName: "bbb",
occurrences: 2,
collectTime: "14-OCT-2018 05:63:42",
status: "unfinished"
},
{
name: "aaa",
mainName: "bbb",
occurrences: 5,
collectTime: "15-OCT-2018 10:56:35",
status: "finished"
},
{
name: "ccc",
mainName: "ddd",
occurrences: 7,
collectTime: "11-OCT-2018 13:12:41",
status: "finished"
},
{
name: "ccc",
mainName: "ddd",
occurrences: 10,
collectTime: "15-OCT-2018 09:03:02",
status: "finished"
},
{
name: "ccc",
mainName: "ddd",
occurrences: 4,
collectTime: "15-OCT-2018 22:36:32",
status: "unfinished"
},
]
Однако я не могу получить массив, который выглядит следующим образом:
[
{
name: "aaa",
mainName: "bbb",
occurrences: 5, // highest occurrences value for the unique combination of name and mainName
collectTime: "15-OCT-2018 10:56:35", // collectTime corresponding to the highest occurrences
finished: 1, // count of the status
unfinished: 2 // count of the status
},
{
name: "ccc",
mainName: "ddd",
occurrences: 10, // highest occurrences value for the unique combination of name and mainName
collectTime: "15-OCT-2018 09:03:02", // collectTime corresponding to the highest occurrences
finished: 2, // count of the status
unfinished: 1 // count of the status
},
]
Я не могу понятькак именно вы используете Array.prototype.reduce (), чтобы получить то, что мне нужно.Я смог добиться определенного прогресса, но не могу получить точный результат.Любое руководство с благодарностью, спасибо!