Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function furniture(input) {
- let totalMoney = 0;
- let items = [];
- let pattern = />>(?<item>\w+)<<(?<price>\d+\.?\d*)!(?<quantity>\d+)/g;
- for (let line of input) {
- if (line === "Purchase") {
- break;
- }
- let valid = pattern.exec(line);
- if (valid) {
- items.push(valid.groups.item);
- totalMoney += Number(valid.groups.price) * Number(valid.groups.quantity);
- }
- }
- console.log("Bought furniture:");
- for (let item of items) {
- console.log(item);
- }
- console.log(`Total money spend: ${totalMoney}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement