Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2021
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function furniture(data)
  2. {
  3.     let pattern = new RegExp(">>(?<furniture>[\\w]+)<<(?<price>[\\d]+[.]?[\\d]+)!(?<quantity>[\\d]+)");
  4.     let command = data.shift()
  5.     let furniture = []
  6.     let currMoney = 0
  7.     let moneyTotal = 0
  8.     let quantity = 0      
  9.     while(command!='Purchase')
  10.     {
  11.         let match = pattern.exec(command)
  12.         if(match!=null)
  13.         {
  14.             furniture.push(match.groups['furniture'])
  15.             currMoney = Number(match.groups['price'])
  16.             quantity = Number(match.groups['quantity'])
  17.             moneyTotal += currMoney*quantity
  18.         }
  19.         command = data.shift()
  20.     }
  21.     console.log('Bought furniture:')
  22.     console.log(furniture.join('\n'))
  23.     console.log(`Total money spend: ${moneyTotal.toFixed(2)}`)
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement