Advertisement
AlexanderHristov

03 - Chore Wars

Dec 8th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(inputArr) {
  2.  
  3.     const regExDishes = /<([a-z\d]+)>/;
  4.     const regExCleaning = /\[([A-Z\d]+)\]/;
  5.     const regExLaundry = /{(.*)}/;
  6.     const regExTime = /[\d]/g;
  7.  
  8.     let dishesTime = 0;
  9.     let cleaningTime = 0;
  10.     let laundryTime = 0;
  11.     let time = 0;
  12.     let result = '';
  13.  
  14.     for (let command of inputArr) {
  15.         if (command.match(regExDishes)) {
  16.             result = command.match(regExDishes)[1];
  17.             time = result.match(regExTime)
  18.                 .reduce((a,b)=>(+a)+(+b), 0);
  19.             dishesTime += time;
  20.         } else if (command.match(regExCleaning)) {
  21.             result = command.match(regExCleaning)[1];
  22.             time = result.match(regExTime)
  23.                 .reduce((a,b)=>(+a)+(+b), 0);
  24.             cleaningTime += time;
  25.         } else if (command.match(regExLaundry)) {
  26.             result = command.match(regExLaundry)[1];
  27.             time = result.match(regExTime)
  28.                 .reduce((a,b)=>(+a)+(+b), 0);
  29.             laundryTime += time;
  30.         }
  31.     }
  32.  
  33.     let totalTime = dishesTime + cleaningTime + laundryTime;
  34.  
  35.     console.log(`Doing the dishes - ${dishesTime} min.`);
  36.     console.log(`Cleaning the house - ${cleaningTime} min.`);
  37.     console.log(`Doing the laundry - ${laundryTime} min.`);
  38.     console.log(`Total - ${totalTime} min.`);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement