Advertisement
dilyana2001

Untitled

Jul 8th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopingList(strArr) {
  2.     let list = strArr.shift().split('!')
  3.     for (let line of strArr) {
  4.         let [command, ...product] = line.split(' ')
  5.         if (command === 'Urgent') {
  6.             if (!list.includes(...product)) {
  7.                 list.unshift(...product)
  8.             }
  9.         } else if (command === 'Unnecessary') {
  10.             if (list.includes(...product)) {
  11.                 let index = list.indexOf(...product)
  12.                 list.splice(index, 1)
  13.             }
  14.         } else if (command === 'Correct') {
  15.             let [oldItem, newItem] = product
  16.             if (list.includes(oldItem)) {
  17.                 let index = list.indexOf(oldItem)
  18.                 list.splice(index, 1, newItem)
  19.             }
  20.         } else if (command === 'Rearrange') {
  21.             if (list.includes(...product)) {
  22.                 let index = list.indexOf(...product)
  23.                 let newItem = list.splice(index, 1)
  24.                 list.push(newItem)
  25.             }
  26.         } else {
  27.             console.log(list.join(', '))
  28.         }
  29.     }
  30.  
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement