Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement