rado_dimitrov66

Untitled

Mar 6th, 2021 (edited)
151
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.     if (command === "Urgent" && products.includes(product) === false) {
  6.       products.unshift(product);
  7.     } else if (command === "Unnecessary" && products.includes(product)) {
  8.       let findProduct = products.indexOf(product);
  9.       products.splice(findProduct, 1);
  10.     } else if (command === "Correct" && products.includes(product)) {
  11.       let findProduct = products.indexOf(product);
  12.       products.splice(findProduct, 1, product2);
  13.     } else if (command === "Rearrange" && products.includes(product)) {
  14.       let findProduct = products.indexOf(product);
  15.       let spliced = products.spliced(findProduct, 1);
  16.       products.push(spliced);
  17.     } else if (command === "Go" && product === "Shopping!") {
  18.       console.log(products.join(", "));
  19.       break;
  20.     }
  21.   }
  22. }
Add Comment
Please, Sign In to add comment