Advertisement
Guest User

Furniture

a guest
Jul 25th, 2020
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function furniture(input) {
  2.     let totalMoney = 0;
  3.     let items = [];
  4.     let pattern = />>(?<item>\w+)<<(?<price>\d+\.?\d*)!(?<quantity>\d+)/g;
  5.     for (let line of input) {
  6.         if (line === "Purchase") {
  7.             break;
  8.         }
  9.         let valid = pattern.exec(line);
  10.         if (valid) {
  11.             items.push(valid.groups.item);
  12.             totalMoney += Number(valid.groups.price) * Number(valid.groups.quantity);
  13.         }
  14.     }
  15.     console.log("Bought furniture:");
  16.     for (let item of items) {
  17.         console.log(item);
  18.     }
  19.     console.log(`Total money spend: ${totalMoney}`);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement