Liliana797979

furniture - fundamentals

Jul 30th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function furniture(array) {
  2.  
  3.     let tempTotal = 0;
  4.     let pattern = /\b(?<name>[A-Z]+[a-z]*)\<{2}(?<price>\d+\.*\d*)\!(?<quantity>\d{1,})/g
  5.     console.log('Bought furniture:')
  6.     for (const str of array) {
  7.         let match = pattern.exec(str)
  8.         while (match !== null) {
  9.             let name = match.groups['name'];
  10.             let price = Number(match.groups['price']);
  11.             let quantity = Number(match.groups['quantity']);
  12.             match = pattern.exec(str);
  13.             console.log(`${name}`);
  14.             tempTotal += (price * quantity);
  15.         }
  16.     }
  17. console.log(`Total money spend: ${tempTotal.toFixed(2)}`)
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment