simeonshopov

Legendary Farming

Apr 15th, 2021
493
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   const input = arr.split(' ');
  3.   let elements = {'shards': 0, 'fragments': 0, 'motes': 0};
  4.   let gatheredJunk = {};
  5.   const legendaryItems = {'fragments': 'Valanyr', 'shards': 'Shadowmourne', 'motes': 'Dragonwrath'};
  6.  
  7.   for (let i = 0; i < input.length - 1; i+=2) {
  8.     const quantity = Number(input[i]);
  9.     const item = input[i+1].toLowerCase();
  10.     if (Object.keys(elements).includes(item)) {
  11.       elements[item] += quantity;
  12.       if (elements[item] >= 250) {
  13.         console.log(`${legendaryItems[item]} obtained!`);
  14.         elements[item] -= 250;
  15.         break;
  16.       }
  17.     } else {
  18.       if (!Object.keys(gatheredJunk).includes(item)) {
  19.         gatheredJunk[item] = 0;
  20.       }
  21.       gatheredJunk[item] += quantity;
  22.     }
  23.   }
  24.  
  25.   for (const element of [...Object.entries(elements)].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))) {
  26.     console.log(`${element[0]}: ${element[1]}`);
  27.   }
  28.  
  29.   for (const junk of [...Object.entries(gatheredJunk)].sort((a, b) => a[0].localeCompare(b[0]))) {
  30.     console.log(`${junk[0]}: ${junk[1]}`);
  31.   }
  32. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×