Lulunga

Furniture regex

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