Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(params) {
- params.pop();
- let competition = {};
- for (let param of params) {
- let [countryName, contestantName, contestantPoints] = param.split(" -> ");
- if (!competition.hasOwnProperty(countryName)) {
- competition[countryName] = {};
- }
- if (!competition[countryName].hasOwnProperty(contestantName)) {
- competition[countryName][contestantName] = Number(contestantPoints);
- } else {
- competition[countryName][contestantName] += Number(contestantPoints);
- }
- }
- Object.entries(competition).forEach(c => {
- let totalPoints = 0;
- Object.values(c[1]).forEach(value => (totalPoints += value));
- console.log(`${c[0]}: ${totalPoints}`);
- Object.entries(c[1]).forEach(contestant =>
- console.log(` -- ${contestant[0]} -> ${contestant[1]}`)
- );
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement