Advertisement
Danny_Berova

01.TravellPlans

Oct 10th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let specialized = ['Programming', 'Hardware maintenance', 'Cooking', 'Translating', 'Designing'];
  2.     let average = ['Driving', 'Managing', 'Fishing', 'Gardening'];
  3.     let clumsy = ['Singing', 'Accounting', 'Teaching', 'Exam-Making', 'Acting', 'Writing', 'Lecturing', 'Modeling', 'Nursing'];
  4.     let specializedCounter = 1;
  5.     let clumsyCounter = 1;
  6.     let sum = 0;
  7.  
  8.     for (const line of input) {
  9.         let [proffesion, gold] = line.split(' : ').filter(t => t !== '');
  10.         proffesion = proffesion.trim();
  11.         if(specialized.includes(proffesion) && gold < 200){
  12.             continue;
  13.         }
  14.         if (specialized.includes(proffesion)) {
  15.             sum += +gold * 0.8;
  16.             if (specializedCounter % 2 === 0) {
  17.                 sum += 200;
  18.             }
  19.             specializedCounter++;
  20.         }
  21.         if(average.includes(proffesion)) {
  22.             sum += +gold;
  23.         }
  24.         if(clumsy.includes(proffesion)) {
  25.             if(clumsyCounter % 2 === 0){
  26.                 gold = +gold * 0.95;
  27.             } else if (clumsyCounter % 3 === 0) {
  28.                 gold = +gold * 0.9;
  29.             }
  30.             sum += +gold;
  31.             clumsyCounter++;
  32.         }
  33.     }
  34.     let result = [];
  35.     result.push(`Final sum: ${sum.toFixed(2)}`);
  36.     if(sum < 1000) {
  37.         result.push(`Mariyka need to earn ${(1000 - sum).toFixed(2)} gold more to continue in the next task.`)
  38.     } else  {
  39.         result.push(`Mariyka earned ${(sum - 1000).toFixed(2)} gold more.`)
  40.     }
  41.     return result.join('\n');
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement