Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shopingList(strArr) {
- let list = strArr.shift().split('!')
- for (let line of strArr) {
- let [command, ...product] = line.split(' ')
- if (command === 'Urgent') {
- if (!list.includes(...product)) {
- list.unshift(...product)
- }
- } else if (command === 'Unnecessary') {
- if (list.includes(...product)) {
- let index = list.indexOf(...product)
- list.splice(index, 1)
- }
- } else if (command === 'Correct') {
- let [oldItem, newItem] = product
- if (list.includes(oldItem)) {
- let index = list.indexOf(oldItem)
- list.splice(index, 1, newItem)
- }
- } else if (command === 'Rearrange') {
- if (list.includes(...product)) {
- let index = list.indexOf(...product)
- let newItem = list.splice(index, 1)
- list.push(newItem)
- }
- } else {
- console.log(list.join(', '))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement