Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bar(arr) {
- let pattern = /%(?<customer>[A-Z][a-z]*)%[^|$%.]*?<(?<product>\w+)>[^|$%.]*?\|(?<count>\d+)\|[^|$%.]*?(?<price>[0-9]+(\.[0-9]+)?)\$/;
- let totalIncome = 0;
- let name;
- let product;
- //let list = {};
- for (let line of arr) {
- if (line === 'end of shift') {
- break;
- }
- if (pattern.test(line)) {
- let totalPrice = 0;
- let tokens = pattern.exec(line);
- name = tokens.groups.customer;
- product = tokens.groups.product;
- let price = Number(tokens.groups.price) * Number(tokens.groups.count);
- totalPrice = price;
- totalIncome+=totalPrice
- console.log(`${name}: ${product} - ${totalPrice.toFixed(2)}`);
- price=0
- }
- }
- console.log(`Total income: ${totalIncome.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement