Advertisement
teofarov13

Untitled

Feb 16th, 2023
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function inventory(arr) {
  2.     let journal = arr.shift().split(", ");
  3.  
  4.     for (let i = 0; i < arr.length; i++) {
  5.         let curr = arr[i].split(" - ");
  6.         let command = curr[0];
  7.         let item = curr[1];
  8.         let index = journal.indexOf(item);
  9.         if (command == "Craft") {
  10.             break;
  11.         }
  12.         switch (command) {
  13.             case "Collect":
  14.                 index = journal.indexOf(item);
  15.                 if (index < 0) {
  16.                     journal.push(item);
  17.                 } break;
  18.             case "Drop":
  19.                 index = journal.indexOf(item);
  20.                 if (index > 0) {
  21.                     journal.splice(index, 1);
  22.                 } break;
  23.             case "Combine Items":
  24.                 index = journal.indexOf(item);
  25.                 if (index < 0) {
  26.                     let splited = item.split(":");
  27.                     let old = splited[0];
  28.                     let newI = splited[1];
  29.                     journal.splice(index ,1,old, newI)
  30.                 } break;
  31.             case "Renew":
  32.                 index = journal.indexOf(item);
  33.                 if (index >= 0) {
  34.                     journal.splice(index, 1);
  35.                     journal.push(item)
  36.                 } break;
  37.         }
  38.     }
  39.     console.log(journal.join(", "));
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement