Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (input) => {
- let bestFlight = {
- name: input.shift(),
- price: Number(input.shift()),
- time: Number(input.shift())
- };
- let line = input.shift();
- while( line !== 'End') {
- let currentFlight = {
- name: line,
- price: Number(input.shift()),
- time: Number(input.shift())
- };
- if(currentFlight.time < bestFlight.time) {
- bestFlight = currentFlight;
- } else if(currentFlight.time == bestFlight.time) {
- if(currentFlight.price < bestFlight.price) {
- bestFlight = currentFlight;
- }
- }
- line = input.shift();
- }
- 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`);
- }
Advertisement
Add Comment
Please, Sign In to add comment