Advertisement
Guest User

Untitled

a guest
Jul 18th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function farming(str = '') {
  2.     let input = str.toLowerCase().split(' ');
  3.     let legendary = {fragments: 0, shards: 0, motes: 0};
  4.     let junk = {}
  5.     let hasToBreak = false;
  6.     while (!hasToBreak) {
  7.         let quantity = +input.shift();
  8.         let material = input.shift();
  9.  
  10.         switch (material) {
  11.             case 'shards':
  12.                 if (!legendary.hasOwnProperty(material)) {
  13.                     legendary[material] = quantity;
  14.                     if (legendary[material] >= 250) {
  15.                         console.log(`Shadowmourne obtained!`);
  16.                         if (legendary[material] > 250) {
  17.                             legendary[material] -= 250
  18.                         }
  19.                         hasToBreak = true;
  20.                     }
  21.                 } else {
  22.                     legendary[material] += quantity;
  23.                     if (legendary[material] >= 250) {
  24.                         console.log(`Shadowmourne obtained!`);
  25.                         if (legendary[material] > 250) {
  26.                             legendary[material] -= 250
  27.                         }
  28.                         hasToBreak = true;
  29.                     }
  30.                 }
  31.                 break;
  32.             case 'fragments':
  33.                 if (!legendary.hasOwnProperty(material)) {
  34.                     legendary[material] = quantity;
  35.                     if (legendary[material] >= 250) {
  36.                         console.log(`Valanyr obtained!`);
  37.                         if (legendary[material] > 250) {
  38.                             legendary[material] -= 250
  39.                         }
  40.                         hasToBreak = true;
  41.                     }
  42.                 } else {
  43.                     legendary[material] += quantity;
  44.                     if (legendary[material] >= 250) {
  45.                         console.log(`Valanyr obtained!`);
  46.                         if (legendary[material] > 250) {
  47.                             legendary[material] -= 250
  48.                         }
  49.                         hasToBreak = true;
  50.                     }
  51.                 }
  52.                 break;
  53.             case 'motes':
  54.                 if (!legendary.hasOwnProperty(material)) {
  55.                     legendary[material] = quantity;
  56.                     if (legendary[material] >= 250) {
  57.                         console.log(`Dragonwrath obtained!`);
  58.                         if (legendary[material] > 250) {
  59.                             legendary[material] -= 250
  60.                         }
  61.                         hasToBreak = true;
  62.                     }
  63.                 } else {
  64.                     legendary[material] += quantity;
  65.                     if (legendary[material] >= 250) {
  66.                         console.log(`Dragonwrath obtained!`);
  67.                         if (legendary[material] > 250) {
  68.                             legendary[material] -= 250
  69.                         }
  70.                         hasToBreak = true;
  71.                     }
  72.                 }
  73.                 break;
  74.             default:
  75.                 if (!junk.hasOwnProperty(material)) {
  76.                     junk[material] = quantity;
  77.  
  78.                 } else {
  79.                     junk[material] += quantity;
  80.  
  81.                 }
  82.                 break;
  83.         }
  84.     }
  85.     let legendItems = Object.entries(legendary).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).forEach(item => {
  86.         console.log(`${item[0]}: ${item[1]}`);
  87.     });
  88.  
  89.     let junkItems = Object.entries(junk).sort((a, b) => a[0].localeCompare(b[0])).forEach(item => {
  90.         console.log(`${item[0]}: ${item[1]}`);
  91.     });
  92. }
  93. farming('123 silver 6 shards 8 shards 5 motes 9 fangs 75 motes 103 MOTES 8 Shards 86 Motes 7 stones 19 silver')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement