Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function legendaryFarming(input) {
- let keyMaterials = { shards: { totalQuantity: 0 }, fragments: { totalQuantity: 0 }, motes: { totalQuantity: 0 } };
- let junk = {};
- let splitted = input.toString().toLowerCase().split(' ');
- for (let i = 0; i < splitted.length; i += 2) {
- material = splitted[i + 1].trim();
- quantity = Number(splitted[i].trim());
- if (material === 'shards' || material === 'fragments' || material === 'motes') {
- keyMaterials[material]["totalQuantity"] += quantity;
- if (keyMaterials[material]["totalQuantity"] >= 250) {
- keyMaterials[material]["totalQuantity"] -= 250;
- if (material === 'shards') {
- console.log(`Shadowmourne obtained!`);
- } else if (material === 'fragments') {
- console.log(`Valanyr obtained!`);
- } else if (material === 'motes') {
- console.log(`Dragonwrath obtained!`);
- }
- break;
- }
- } else {
- if (junk.hasOwnProperty(material) === false) {
- junk[material] = {
- totalQuantity: 0,
- };
- }
- junk[material]["totalQuantity"] += quantity;
- }
- }
- let result = Object.entries(keyMaterials).sort((a, b) => b[1]["totalQuantity"] - a[1]["totalQuantity"] || a[0].localeCompare(b[0]));
- for (const key of result) {
- console.log(`${key[0]}: ${key[1]['totalQuantity']}`);
- }
- let junkResult = Object.entries(junk).sort();
- for (const key of junkResult) {
- console.log(`${key[0]}: ${key[1]['totalQuantity']}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement