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(" ");
- if (command === "Urgent" && products.includes(product) === false) {
- products.unshift(product);
- } else if (command === "Unnecessary" && products.includes(product)) {
- let findProduct = products.indexOf(product);
- products.splice(findProduct, 1);
- } else if (command === "Correct" && products.includes(product)) {
- let findProduct = products.indexOf(product);
- products.splice(findProduct, 1, product2);
- } else if (command === "Rearrange" && products.includes(product)) {
- let findProduct = products.indexOf(product);
- let spliced = products.spliced(findProduct, 1);
- products.push(spliced);
- } else if (command === "Go" && product === "Shopping!") {
- console.log(products.join(", "));
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment