AreWe

best flight

Feb 7th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. (input) => {
  2. let bestFlight = {
  3. name: input.shift(),
  4. price: Number(input.shift()),
  5. time: Number(input.shift())
  6. };
  7.  
  8. let line = input.shift();
  9. while( line !== 'End') {
  10. let currentFlight = {
  11. name: line,
  12. price: Number(input.shift()),
  13. time: Number(input.shift())
  14. };
  15. if(currentFlight.time < bestFlight.time) {
  16. bestFlight = currentFlight;
  17. } else if(currentFlight.time == bestFlight.time) {
  18. if(currentFlight.price < bestFlight.price) {
  19. bestFlight = currentFlight;
  20. }
  21. }
  22. line = input.shift();
  23. }
  24.  
  25. console.log(`Ticket found for flight ${bestFlight.name} costs ${(bestFlight.price*1.96).toFixed(2)} leva with ${Math.floor(bestFlight.time/60)}h ${Math.floor(bestFlight.time%60)}m stay`);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment