Advertisement
kstoyanov

01. Furniture js fundamentals

Jul 24th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const pattern = />>([a-zA-Z)]+)<<(\d+\.?\d+)!(\d+)/gm;
  3.  
  4.   const makeOneString = args.join('\n');
  5.  
  6.   const arr = Array.from(makeOneString.matchAll(pattern));
  7.  
  8.  
  9.   console.log('Bought furniture:');
  10.   let cost = 0;
  11.   arr.forEach((match) => {
  12.     const [, name, price, quantity] = match;
  13.  
  14.     if (name !== 'Purchase') {
  15.       console.log(`${name}`);
  16.     }
  17.     cost += Number(price) * Number(quantity);
  18.   });
  19.  
  20.   console.log(`Total money spend: ${cost.toFixed(2)}`);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement