Advertisement
dilyana2001

Untitled

Jun 25th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gladiatorInventory(arr) {
  2.     let inventory = arr.shift().split(' ');
  3.     arr.map(row => {
  4.         let [command, item] = row.split(' ');
  5.         if (command === 'Buy') {
  6.             if (!inventory.includes(item)) {
  7.                 inventory.push(item);
  8.             }
  9.         } else if (command === 'Trash') {
  10.             if (inventory.includes(item)) {
  11.                 inventory.splice(inventory.indexOf(item), 1)
  12.             }
  13.         } else if (command === 'Repair') {
  14.             if (inventory.includes(item)) {
  15.                 inventory.splice(inventory.indexOf(item), 1);
  16.                 inventory.push(item);
  17.             }
  18.         } else if (command === 'Upgrade') {
  19.             let exist = item.split('-');
  20.             if (inventory.includes(exist[0])) {
  21.                 item = exist.join(':')
  22.                 inventory.splice(inventory.indexOf(exist[0]) + 1, 0, item);
  23.             }
  24.         }
  25.     })
  26.     return inventory.join(' ');
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement