Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gladiatorInventory(commands) {
- let inventory = commands.shift().split(' ');
- while (commands.length !== 0) {
- let command = commands.shift().split(' ');
- if (!inventory.includes(command[1]) && command[0] === 'Buy') {
- inventory.push(command[1]);
- }
- if (command[0] === 'Trash' && inventory.includes(command[1])) {
- inventory.splice(inventory.indexOf(command[1]), 1);
- }
- if (command[0] === 'Repair' && inventory.includes(command[1])) {
- inventory.splice(inventory.indexOf(command[1]), 1);
- inventory.push(command[1]);
- }
- if (command[0] === 'Upgrade') {
- let current = command[1].split('-');
- if (inventory.includes(current[0])) {
- inventory.splice(inventory.indexOf(current[0]) + 1, 0, current[0] + ':' + current[1]);
- }
- }
- }
- console.log(inventory.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement