Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shoppingList(input) {
- let list = input.shift().split('!');
- while (input[0] !== "Go Shopping!") {
- [command, product, newProduct] = input.shift().split(' ');
- if (command === "Urgent" && !list.includes(product)) {
- list.unshift(product);
- } else if (command === "Unnecessary" && list.includes(product)) {
- list.splice(list.indexOf(product), 1);
- } else if (command === "Correct" && list.includes(product)) {
- list.splice(list.indexOf(product), 1, newProduct);
- } else if (command === "Rearrange" && list.includes(product)) {
- list.push(list.splice(list.indexOf(product), 1));
- }
- }
- console.log(list.join(", "));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement