Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shopping(input) {
- let products = input.shift().split("!");
- for (let i of input) {
- let [command, product, product2] = i.split(" ");
- let check = products.includes(product);
- if (command === "Urgent" && check === false) {
- products.unshift(product);
- } else if (command === "Unnecessary" && check) {
- let findProduct = products.indexOf(product);
- products.splice(findProduct, 1);
- } else if (command === "Correct" && check) {
- let findProduct = products.indexOf(product);
- products.splice(findProduct, 1, product2);
- } else if (command === "Rearrange" && check) {
- let findProduct = products.indexOf(product);
- let spliced = products.spliced(findProduct, 1);
- products.push(spliced);
- } else if (command === "Go") {
- console.log(products.join(", "));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement