1 votes

How to add properties of an object?

I have 3 results with the properties teams and medals: Gold, bronze and silver. I need to total the medals by country, that is, add the 3 types of medals and assign the value to each country that corresponds.

I can't use either booksellers or regular experiences.

if you can help me I thank you-.

This is my code:

0voto

Juan Points 71

This solution is super vanilla Javascript. Simply use a list with indexes of the name of the country, and add up the medals of each country.
Then to maintain the structure of objects because I convert that list (array) to a list of objects {team:'', totalMedals:0}

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X