I have this type of array of objects:
[{
ID: 'MCHARPENT ',
REA: 4,
STO: 90,
EFFCAR: 178,
},
{
ID: 'I050MCHE ',
REA: 0,
STO: 125,
EFFCAR: 228,
},
{
ID: 'I050MCHE ',
REA: 0,
STO: 106,
EFFCAR: 231,
},
{
ID: 'DBALLAVOINE',
REA: 0,
STO: 107,
EFFCAR: 172,
},
{
ID: 'DBALLAVOINE',
REA: 20,
STO: 30,
EFFCAR: 100,
}]
I'm searching a way to group them when the IDs are:
- either the same (second and third objects)
- or when one starts with 3 letters that are found after 'I050', as in this case the letters 'MCH', which is the beginning of the first ID and is after I050 in the second
If there is a match, the ID without 'I050' take over the name. In addition, I have to sum the other values.
The result should look like this with these four objects :
{
ID: 'MCHARPENT',
REA: 4,
STO: 321,
EFFCAR: 637,
},
{
ID: 'DBALLAVOINE',
REA: 20,
STO: 137,
EFFCAR: 272,
}]
I don't manage to find a way to group by with these conditions.