Advertisement
Spocoman

09. Gladiator Inventory

Feb 9th, 2022
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gladiatorInventory(commands) {
  2.     let inventory = commands.shift().split(' ');
  3.     while (commands.length !== 0) {
  4.         let command = commands.shift().split(' ');
  5.         if (!inventory.includes(command[1]) && command[0] === 'Buy') {
  6.             inventory.push(command[1]);
  7.         }
  8.         if (command[0] === 'Trash' && inventory.includes(command[1])) {
  9.             inventory.splice(inventory.indexOf(command[1]), 1);
  10.         }
  11.         if (command[0] === 'Repair' && inventory.includes(command[1])) {
  12.             inventory.splice(inventory.indexOf(command[1]), 1);
  13.             inventory.push(command[1]);
  14.         }
  15.         if (command[0] === 'Upgrade') {
  16.             let current = command[1].split('-');
  17.             if (inventory.includes(current[0])) {
  18.                 inventory.splice(inventory.indexOf(current[0]) + 1, 0, current[0] + ':' + current[1]);
  19.             }
  20.         }
  21.     }
  22.     console.log(inventory.join(' '));
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement