Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function barIncome(arr) {
- let rgx = /%(?<name>[A-Z][a-z]+)%.*?<(?<product>\w+)>.*?\|(?<count>\d+)\|.*?(?<price>\d+(?:.\d+)?)\$/;
- let total = 0;
- while (arr[0] != 'end of shift') {
- let line = arr.shift();
- let match = rgx.exec(line);
- if (match) {
- let group = match['groups'];
- let money = Number(group.count) * Number(group.price);
- total += money;
- console.log(`${group.name}: ${group.product} - ${money.toFixed(2)}`);
- }
- }
- console.log(`Total income: ${total.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment