Advertisement
rado_dimitrov66

Problem 2

Mar 6th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopping(input) {
  2.   let products = input.shift().split("!");
  3.   for (let i of input) {
  4.     let [command, product, product2] = i.split(" ");
  5.     let check = products.includes(product);
  6.     if (command === "Urgent" && check === false) {
  7.       products.unshift(product);
  8.     } else if (command === "Unnecessary" && check) {
  9.       let findProduct = products.indexOf(product);
  10.       products.splice(findProduct, 1);
  11.     } else if (command === "Correct" && check) {
  12.       let findProduct = products.indexOf(product);
  13.       products.splice(findProduct, 1, product2);
  14.     } else if (command === "Rearrange" && check) {
  15.       let findProduct = products.indexOf(product);
  16.       let spliced = products.spliced(findProduct, 1);
  17.       products.push(spliced);
  18.     } else if (command === "Go") {
  19.       console.log(products.join(", "));
  20.     }
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement