Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function inventory(input) {
- let collectedItems = input[0].split(", ");
- for (let i = 1; input[i] !== "Craft!"; i++) {
- [command, item] = input[i].split(" - ");
- if (command === "Collect") {
- if (!collectedItems.includes(item)) {
- collectedItems.push(item);
- }
- } else if (command === "Drop") {
- if (collectedItems.includes(item)) {
- collectedItems.splice(collectedItems.indexOf(item), 1);
- }
- } else if (command === "Combine Items") {
- [oldItem, newItem] = item.split(':');
- if (collectedItems.includes(oldItem)) {
- collectedItems.splice(collectedItems.indexOf(oldItem) + 1, 0, newItem);
- }
- } else {
- if (collectedItems.includes(item)) {
- collectedItems.splice(collectedItems.indexOf(item), 1);
- collectedItems.push(item);
- }
- }
- }
- console.log(collectedItems.join(", "));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement