Advertisement
AlexanderHristov

Problem 3 – SoftUni Bar Income

Dec 7th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(inputArr) {
  2.  
  3.     inputArr.pop();
  4.     let regExValidator = /%([A-Z][a-z]+)%[^|$%.]*<(\w+)>[^|$%.]*\|(\d+)\|[^|$%.0-9]*(\d+|\d+\.\d+)\$/;
  5.     let totalIncome = 0;
  6.     let bill = 0;
  7.  
  8.     for (let order of inputArr) {
  9.         if (order.match(regExValidator)) {
  10.  
  11.             let [, customer, product, count, price] = order.match(regExValidator);
  12.  
  13.             bill = count * price;
  14.  
  15.             console.log(`${customer}: ${product} - ${bill.toFixed(2)}`);
  16.             totalIncome += bill;
  17.         }
  18.     }
  19.  
  20.     console.log(`Total income: ${totalIncome.toFixed(2)}`);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement