ErolKZ

Untitled

Nov 19th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let pattern = /(?<custm>\%[A-Z][a-z]+\%).*(?<prod>\<\w+\>).*(?<count>\|\d+\|).*(?<price>\d+\$|\d+[\.]\d+\$)/g;
  5.  
  6. let i = 0;
  7.  
  8. let arr = [];
  9.  
  10.  
  11.  
  12. while (input[i] !== 'end of shift') {
  13.  
  14. if ((customer = pattern.exec(input[i]) !== null) {
  15.  
  16. console.log(customer[0]);
  17.  
  18. }
  19.  
  20.  
  21. i++;
  22.  
  23. }
  24.  
  25.  
  26. // console.log(`{customerName}: {product} - {totalPrice}`);
  27.  
  28. // console.log(`Total income: {income}`);
  29.  
  30. }
  31.  
  32.  
  33. solve(
  34.  
  35. ['%George%<Croissant>|2|10.3$',
  36.  
  37. '%Peter%<Gum>|1|1.3$',
  38.  
  39. '%Maria%<Cola>|1|2.4$',
  40.  
  41. 'end of shift']
  42.  
  43. );
  44.  
Advertisement
Add Comment
Please, Sign In to add comment