Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const pattern = />>([a-zA-Z)]+)<<(\d+\.?\d+)!(\d+)/gm;
- const makeOneString = args.join('\n');
- const arr = Array.from(makeOneString.matchAll(pattern));
- console.log('Bought furniture:');
- let cost = 0;
- arr.forEach((match) => {
- const [, name, price, quantity] = match;
- if (name !== 'Purchase') {
- console.log(`${name}`);
- }
- cost += Number(price) * Number(quantity);
- });
- console.log(`Total money spend: ${cost.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement