nikolayneykov

Untitled

Feb 23rd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let peshoInventory = arr.shift().split(' ');
  3.     for (let param of arr) {
  4.         let currentElement = param.split(" ");
  5.         let command = currentElement[0];
  6.         let equipment = currentElement[1];
  7.  
  8.         if (command === 'Upgrade') {
  9.             equipment = currentElement[1].split("-")[0];
  10.         }
  11.  
  12.         let index = peshoInventory.indexOf(equipment);
  13.  
  14.         if (command === "Buy" && index === -1) {
  15.             peshoInventory.push(equipment);
  16.         } else if (command === "Trash" && index !== -1) {
  17.             peshoInventory.splice(index, 1)
  18.         } else if (command === "Repair" && index !== -1) {
  19.             let forRepair = peshoInventory.splice(index, 1);
  20.             peshoInventory.push(forRepair);
  21.         } else if (command === "Upgrade" && index !== -1) {
  22.             let expansion = currentElement[1].replace('-', ':');
  23.             peshoInventory.splice(index + 1, 0, expansion)
  24.         }
  25.     }
  26.     console.log(peshoInventory.join(" "))
  27. }
Advertisement
Add Comment
Please, Sign In to add comment