Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let finalList = {}
- input = input[0].split(', ')
- for (let inp of input) {
- if (inp.includes('-')) {
- let [game, price] = inp.split('-')
- price = +price
- finalList[game] = {
- price: price
- }
- } else {
- let [game, dlc] = inp.split(':')
- if (finalList.hasOwnProperty(game)) {
- finalList[game].dlcs = dlc
- finalList[game].price += finalList[game].price * 0.2
- }
- }
- }
- let wihDlcs = Object.entries(finalList)
- .filter(x => x[1].dlcs)
- .map(([key, value]) => [
- key,
- { price: (value.price / 2).toFixed(2), dlcs: value.dlcs }
- ])
- .sort((a, b) => a[1].price - b[1].price)
- .map(g => `${g[0]} - ${g[1].dlcs} - ${g[1].price}`)
- .join('\n')
- let noDlcs = Object.entries(finalList)
- .filter(x => !x[1].dlcs)
- .map(([key, value]) => [key, { price: (value.price * 0.8).toFixed(2) }])
- .sort((a, b) => {
- return b[1].price - a[1].price
- })
- .map(g => `${g[0]} - ${g[1].price}`)
- .join('\n')
- console.log(wihDlcs + '\n' + noDlcs)
- }
- solve([
- 'WitHer 3-50, FullLife 3-60, WitHer 3:Blood and Beer, Cyberfunk 2077-120, League of Leg Ends-10, League of Leg Ends:DoaT'
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement