Advertisement
nikolayneykov

Untitled

Apr 10th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.   let finalList = {}
  3.   input = input[0].split(', ')
  4.   for (let inp of input) {
  5.     if (inp.includes('-')) {
  6.       let [game, price] = inp.split('-')
  7.       price = +price
  8.       finalList[game] = {
  9.         price: price
  10.       }
  11.     } else {
  12.       let [game, dlc] = inp.split(':')
  13.       if (finalList.hasOwnProperty(game)) {
  14.         finalList[game].dlcs = dlc
  15.         finalList[game].price += finalList[game].price * 0.2
  16.       }
  17.     }
  18.   }
  19.  
  20.   let wihDlcs = Object.entries(finalList)
  21.     .filter(x => x[1].dlcs)
  22.     .map(([key, value]) => [
  23.       key,
  24.       { price: (value.price / 2).toFixed(2), dlcs: value.dlcs }
  25.     ])
  26.     .sort((a, b) => a[1].price - b[1].price)
  27.     .map(g => `${g[0]} - ${g[1].dlcs} - ${g[1].price}`)
  28.     .join('\n')
  29.  
  30.   let noDlcs = Object.entries(finalList)
  31.     .filter(x => !x[1].dlcs)
  32.     .map(([key, value]) => [key, { price: (value.price * 0.8).toFixed(2) }])
  33.     .sort((a, b) => {
  34.       return b[1].price - a[1].price
  35.     })
  36.     .map(g => `${g[0]} - ${g[1].price}`)
  37.     .join('\n')
  38.  
  39.   console.log(wihDlcs + '\n' + noDlcs)
  40. }
  41. solve([
  42.   'WitHer 3-50, FullLife 3-60, WitHer 3:Blood and Beer, Cyberfunk 2077-120, League of Leg Ends-10, League of Leg Ends:DoaT'
  43. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement