Advertisement
kstoyanov

03. SoftUni Bar Income js fundamentals

Jul 28th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   let income = 0;
  3.  
  4.   args.forEach((str) => {
  5.     if (str !== 'end of shift') {
  6.       const newRe = /%([A-Z][a-z]+)%[^|$%.]*<(\w+)>[^|$%.]*\|(\d+)\|[^|$%.]*?([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\$/gm.exec(str);
  7.  
  8.       if (newRe !== null) {
  9.         const [, customerName, product, count, price] = newRe;
  10.         const totalPrice = Number(count) * Number(price);
  11.         income += totalPrice;
  12.         console.log(`${customerName}: ${product} - ${totalPrice.toFixed(2)}`);
  13.       }
  14.     }
  15.   });
  16.  
  17.   console.log(`Total income: ${income.toFixed(2)}`);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement