Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- console.log("Bought furniture:");
- let totalSum = 0;
- input.forEach((line) => {
- const pattern = />>(?<name>[a-zA-Z]+)<<(?<price>[0-9]+[.]?[0-9]*)[!]{1}(?<quantity>[0-9]+)/gm;
- let result = pattern.exec(line);
- if (result) {
- console.log(result.groups.name);
- totalSum += Number(result.groups.price) * Number(result.groups.quantity);
- }
- });
- console.log(`Total money spend: ${totalSum.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment