I'm facing a challenge with an array structure:
const originalArray = [
{
name: "a",
value: 1
},
{
name: "a",
value: 2
},
{
name: "a",
value: 3
},
{
name: "b",
value: 0
},
{
name: "b",
value: 1
}
];
My goal is to transform this array into the following format:
const newArray = [
{
name: "a",
value: 2
},
{
name: "b",
value: 0.5
}
]
The new array should contain each unique name as an object with the average value.
Any suggestions on how to achieve this efficiently?