Професионална програма
simon.kan1 avatar simon.kan1 1 Точки

Gladiator Inventory

Здравейте, малко помощ за тази задачка 09. Gladiator Inventory от Arrays Advanced Exercise. Други условия не виждам, и с тези 2 дадени инпута, не знам какво друго да направя?
Judge ми дава 70/100


9. *Gladiator Inventory

As a gladiator, Peter has cool Inventory. He loves to buy new equipment. You are given Peter’s inventory with all of his equipment -> strings, separated by whitespace.

You may receive the following commands:

  • Buy {equipment}
  • Trash {equipment}
  • Repair {equipment}
  • Upgrade {equipment}-{upgrade}

If you receive Buy command, you should add the equipment at last position in the inventory, but only if it isn't bought already.

If you receive Trash command, delete the equipment if it exists.

If you receive Repair command, you should repair the equipment if it exists and place it on last position.

If you receive Upgrade command, you should check if the equipment exists and insert after it the upgrade in the following format: "{equipment}:{upgrade}";

Input / Consrtaints

You will receive an array of strings. Each element of the array is a command.

  • In the first input element, you will receive Peter's inventory – sequence of equipment names, separated by space.


As output you must print Peter's inventory.


  • The command will always be valid.
  • The equipment and Upgrade will be strings and will contain any character, except '-'.
  • Allowed working time / memory: 100ms / 16MB.

Scroll down to see examples.





['SWORD Shield Spear',

'Buy Bag',

'Trash Shield',

'Repair Spear',

'Upgrade SWORD-Steel']

SWORD SWORD:Steel Bag Spear

We receive the inventory => SWORD, Shield, Spear

We Buy Bag => SWORD, Shield, Spear, Bag

Trash Shield => SWORD, Spear, Bag

Repair Spear => SWORD, Bag, Spear

We add Upgrade => SWORD, SWORD:Steel, Bag,Spear

We print the inventory.

['SWORD Shield Spear',

'Trash Bow',

'Repair Shield',

'Upgrade Helmet-V']

SWORD Spear Shield


JavaScript Fundamentals
krasizorbov avatar krasizorbov 373 Точки


Съвсем малък е проблема, просто не си догледал че при Upgrade командата се печата "{equipment}:{upgrade}" така че ето с малка поправка:

function upgrade(eqp) {
    let item = eqp.split("-");
    for (let i = 0; i < inventory.length; i++) {
      if (item[0] === inventory[i]) {
        let newItem = item[0] + ":" + item[1];
        inventory.splice(i + 1, 0, newItem);
    return inventory;

simon.kan1 avatar simon.kan1 1 Точки