Liliana797979

bar income - fundamentals

Aug 4th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function barIncome(arr) {
  2.     let rgx = /%(?<name>[A-Z][a-z]+)%.*?<(?<product>\w+)>.*?\|(?<count>\d+)\|.*?(?<price>\d+(?:.\d+)?)\$/;
  3.     let total = 0;
  4.  
  5.     while (arr[0] != 'end of shift') {
  6.         let line = arr.shift();
  7.         let match = rgx.exec(line);
  8.  
  9.         if (match) {
  10.             let group = match['groups'];
  11.             let money = Number(group.count) * Number(group.price);
  12.             total += money;
  13.             console.log(`${group.name}: ${group.product} - ${money.toFixed(2)}`);
  14.         }
  15.     }
  16.  
  17.     console.log(`Total income: ${total.toFixed(2)}`);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment