Advertisement
bebo231312312321

Untitled

Mar 16th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function softuniBarIncome(arr) {
  2.     let endShift = arr.splice(arr.indexOf(`end of shift`));
  3.     let regExPat = /%(?<customer>[A-Z][a-z]*)%.*<(?<product>\w+)>.*?\|(?<count>\d+)\|.*?(?<price>[\d]+[.]*\d+)\$/g
  4.     let totalSum = 0;
  5.     for (const line of arr) {
  6.         let matches = line.matchAll(regExPat);
  7.        
  8.         for (const match of matches) {
  9.             let customerSpent = Number(match.groups.count * match.groups.price);
  10.             console.log(`${match.groups.customer}: ${match.groups.product} - ${customerSpent.toFixed(2)}`);
  11.             totalSum += customerSpent;
  12.         }
  13.     }
  14.     console.log(`Total income: ${totalSum.toFixed(2)}`);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement