Advertisement
nikolayneykov

Untitled

Mar 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.     let days = Number(params.shift());
  3.     let budget = Number(params.shift());
  4.     let peopleCount = Number(params.shift());
  5.     let fuelPrice = Number(params.shift());
  6.     let foodPrice = Number(params.shift());
  7.     let hotelPrice = Number(params.shift());
  8.  
  9.     foodPrice *= days * peopleCount;
  10.     hotelPrice *= days * peopleCount;
  11.  
  12.     if (peopleCount > 10) {
  13.         hotelPrice *= 0.75;
  14.     }
  15.  
  16.     let totalExpenses = foodPrice + hotelPrice;
  17.     let currentDay = 1;
  18.    
  19.     for (let distance of params) {
  20.         if (totalExpenses > budget) {
  21.             break;
  22.         }
  23.  
  24.         totalExpenses += fuelPrice * Number(distance);
  25.  
  26.         if (currentDay % 3 === 0 || currentDay % 5 === 0) {
  27.             totalExpenses *= 1.4;
  28.         }
  29.  
  30.         if (currentDay % 7 === 0) {
  31.             totalExpenses -= totalExpenses / peopleCount;
  32.         }
  33.  
  34.         currentDay++;
  35.     }
  36.  
  37.     console.log(budget >= totalExpenses ?
  38.         `You have reached the destination. You have ${(budget - totalExpenses).toFixed(2)}$ budget left.` :
  39.         `Not enough money to continue the trip. You need ${(totalExpenses - budget).toFixed(2)}$ more.`)
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement