Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function softUniBarIncome(lines) {
- let command = lines.pop();
- let totalIncome = 0;
- let pattern = /%(?<customer>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>\d+)\|[^|$%\.0-9]*(?<price>[0-9]+.?\d*)\$/g;
- while((data = pattern.exec(lines)) !== null) {
- let customer = data.groups['customer'];
- let product = data.groups['product'];
- let quantity = data.groups['count'];
- let price = data.groups['price'];
- let orderPrice = quantity * price;
- console.log(`${customer}: ${product} - ${orderPrice.toFixed(2)}`);
- totalIncome += orderPrice;
- }
- if (command === 'end of shift') {
- console.log(`Total income: ${totalIncome.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement