Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let regEx = /^%(?<name>[A-Z][a-z]*)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<quantity>[0-9]+)\|[^|$%.]*?(?<price>[0-9]+\.*[0-9]*)\$$/
- let totalIncome = 0;
- for (const line of input) {
- if(line === 'end of shift'){
- break;
- }
- if(line.match(regEx)!==null){
- let result = line.match(regEx).groups;
- let name = result.name;
- let product = result.product;
- let quantity = Number(result.quantity);
- let price = Number(result.price);
- console.log(`${name}: ${product} - ${(price*quantity).toFixed(2)}`);
- totalIncome += price*quantity;
- }
- }
- console.log(`Total income: ${totalIncome.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment