vikkktor

mid_exam-burgerBus

Oct 24th, 2021
815
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let arr = input
  3.     let numberOfCities = arr.shift();
  4.  
  5.     let totalProfit = 0
  6.     let totalExpenses = 0
  7.     citiesVisit = 0
  8.  
  9.     for (let i = 0; i<numberOfCities * 3; i+=3) {
  10.         citiesVisit++
  11.  
  12.         let cityname = arr[i]
  13.         let cityProfit = arr[i + 1]
  14.         let cityExpenses = arr[i + 2]
  15.  
  16.         if (citiesVisit % 5 == 0) {      // rainy day, no special evenets
  17.             // losses 10% of the money
  18.             cityProfit = cityProfit*0.9
  19.         } else if (citiesVisit % 3 == 0) {      // special event
  20.             // + 50% expenses
  21.             cityExpenses = cityExpenses*1.5
  22.         }
  23.  
  24.         totalProfit = totalProfit + Number(cityProfit) - Number(cityExpenses)
  25.         console.log(`In ${cityname} Burger Bus earned ${(cityProfit-cityExpenses).toFixed(2)} leva.`)
  26.     }
  27.     console.log(`Burger Bus total profit: ${totalProfit.toFixed(2)} leva.`)
  28. }
RAW Paste Data