Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let finalList = {}
- for (let inp of input) {
- let [country, name, points] = inp.split(' -> ')
- points = +points
- if (inp === 'END') {
- break
- }
- if (!finalList.hasOwnProperty(country)) {
- finalList[country] = {
- params: [],
- totalpoints: 0
- }
- }
- let player = finalList[country].params.find(x => x[0] === name)
- if (!player) {
- finalList[country].params.push([name, 0])
- player = finalList[country].params.find(x => x[0] === name)
- }
- player[1] += points
- finalList[country].totalpoints += points
- }
- let s = Object.entries(finalList).sort((a, b) => {
- return b[1].totalpoints - a[1].totalpoints
- })
- for (let param of s) {
- console.log(`${param[0]}: ${param[1].totalpoints}`)
- for (let p of param[1].params) {
- console.log(` -- ${p[0]} -> ${p[1]}`)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement