Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let totalIncome = 0;
- let index = arr.indexOf('end of shift');
- arr.splice(index, 1);
- arr.forEach(line => {
- let pattern = /%([A-Z][a-z]+)%[^|,$%]*<(\w+)>[^|,$%]*\|([0-9]+)\|[^|,$%0-9]*([0-9]+\.?\d*)\$/gm;
- let result = pattern.exec(line);
- if (result) {
- let name = result[1];
- let product = result[2];
- let count = Number(result[3]);
- let price = Number(result[4]);
- let currentSum = count * price;
- totalIncome += currentSum;
- console.log(`${name}: ${product} - ${currentSum.toFixed(2)}`);
- }
- });
- console.log(`Total income: ${totalIncome.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement