-
-
Save sammarcus/57fbbf435160e5a2ef6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flights = $("div:contains('Best flights'):last").parent().children(); | |
if (flights.length === 0) { | |
flights = $("div:contains('Choose an outbound'):last").parent().parent().children()[1]; | |
flights = $($(flights).children()[0]).children(); | |
} | |
var avg_time = 0; | |
var avg_price = 0; | |
flights.toArray().forEach(function (elm, ind, arr) { | |
if ($(elm).attr("iti") != undefined) { | |
var valid_data = ($(elm).children()[0]); | |
var child_data = $(valid_data).children()[0]; | |
child_data = $(child_data).children()[0]; | |
var price_hooray_finally = $($(child_data).children()[0]).text(); | |
price_hooray_finally = price_hooray_finally.slice(1); | |
var time = $($(valid_data).children()[2]); | |
time = $(time).first().text().split(" "); | |
var time_hours = (time[0] !== "from") ? time[0] : time[1]; | |
var time_minutes = (time[0] !== "from") ? time[1] : time[2]; | |
time = parseInt(time_hours.slice(0,-1)) + parseInt(time_minutes.slice(0,-1))/60; | |
avg_price += parseInt(price_hooray_finally); | |
avg_time += time; | |
} | |
}); | |
avg_price = avg_price / flights.length; | |
avg_time = avg_time / flights.length; | |
console.log("Average Price: ", avg_price); | |
console.log("Average Time: ", avg_time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment