I have for example this array:
[
{
"name": "Daniel",
"points": 10,
},
{
"name": "Ana",
"points": 20
},
{
"name": "Daniel",
"points": 40
}
]
And i want delete one "Daniel" and points to the sum of all whit the same name like this:
[
{
"name": "Daniel",
"points": 50,
},
{
"name": "Ana",
"points": 20
}
]
How can i transform it?
I was trying whit two bucles:
for name in persons {
for name2 in persons {
if name == name2 {
//remove the duplicate one and sum his points
}
}
}
but maybe there is a way too much easier than this one