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