# Untitled

a guest
Jul 30th, 2019
231
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // Vapor winter sale
2. function solve(input) {
3.     let list = input.shift().split(", ");
4.     let prices = {};
5.
6.     // Filling the object
7.     list.forEach((game) => {
8.         if(game.includes('-')) {
9.             let [ gameName, price ] = game.split("-");
10.             if (!prices.hasOwnProperty(gameName)) {
11.                 prices[gameName] = [+price];
12.             }
13.         } else if (game.includes(':')) {
14.             let [ gameName, dlc ] = game.split(":");
15.             if (prices.hasOwnProperty(gameName)) {
16.                 let newPrice = Number(prices[gameName]) + Number(prices[gameName])/5;
17.                 prices[gameName] = [newPrice];
18.                 prices[gameName].push(dlc);
19.             }
20.         }
21.     });
22.
23.     // Calculating the final prices
24.     for (let [game, values] of Object.entries(prices)) {
25.         let price = values[0];
26.         if (values.length > 1) {
27.             price -= price/2;
28.             prices[game][0] = price;
29.         } else {
30.             price -= price/5;
31.             prices[game][0] = price;
32.         }
33.     }
34.
35.     // Sorting
36.
37. console.log(prices);
38.
39. }
40. //
41. // solve(
42. //     [
43. //         "WitHer 3-50, FullLife 3-60, WitHer 3:Blood and Beer, Cyberfunk 2077-120, League of Leg Ends-10, League of Leg Ends:DoaT"
44. //     ]
45. // );
RAW Paste Data