Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(inputArr) {
- let inventoryArr = inputArr.shift();
- inventoryArr = inventoryArr.split(' ');
- for (let currentArr of inputArr) {
- let currentCommand = currentArr.split(' ');
- let weapon = currentCommand[1];
- if (currentCommand.includes('Buy')) {
- if (!inventoryArr.includes(weapon)) {
- inventoryArr.push(weapon);
- }
- } else if (currentCommand.includes('Trash')) {
- if (inventoryArr.includes(weapon)) {
- inventoryArr.splice(inventoryArr.indexOf(weapon), 1);
- }
- } else if (currentCommand.includes('Repair')) {
- if (inventoryArr.includes(weapon)) {
- inventoryArr.push(weapon);
- inventoryArr.splice(inventoryArr.indexOf(weapon), 1);
- }
- } else if (currentCommand.includes('Upgrade')) {
- let weaponUpgrade = weapon.replace('-',':');
- weapon = weapon.split('-');
- let upgrade = weapon[0];
- if (inventoryArr.includes(upgrade)) {
- inventoryArr.splice(inventoryArr.indexOf(upgrade)+1, 0, weaponUpgrade);
- }
- }
- }
- console.log(inventoryArr.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment