Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3. arr.pop();
  4. let totalIncome = 0;
  5. arr.forEach((line) => {
  6. let pattern = /%([A-Z][a-z]+)%[^|$%.]*<(\w+)>[^|$%.]*\|([0-9]+)\|[^|$%.]*?([0-9]+\.?[0-9]*)\$/gm;
  7.  
  8. let result = pattern.exec(line);
  9. let currentSum = Number(result[3]) * Number(result[4]);
  10. console.log(`${result[1]}: ${result[2]} - ${currentSum.toFixed(2)}`);
  11. totalIncome += currentSum;
  12. });
  13. console.log(`Total income: ${totalIncome.toFixed(2)}`);
  14.  
  15. }
  16.  
  17. solve(['%George%<Croissant>|2|10.3$',
  18. '%Peter%<Gum>|1|1.3$',
  19. '%Maria%<Cola>|1|2.4$',
  20. 'end of shift']
  21. );
  22.  
  23. solve([ '%InvalidName%<Croissant>|2|10.3$',
  24. '%Peter%<Gum>1.3$',
  25. '%Maria%<Cola>|1|2.4',
  26. '%Valid%<Valid>valid|10|valid20$',
  27. 'end of shift' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement