Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. var flights = $("div:contains('Best flights'):last").parent().children();
  2. if (flights.length === 0) {
  3. flights = $("div:contains('Choose an outbound'):last").parent().parent().children()[1];
  4. flights = $($(flights).children()[0]).children();
  5. }
  6.  
  7. var avg_time = 0;
  8. var avg_price = 0;
  9. flights.toArray().forEach(function (elm, ind, arr) {
  10. if ($(elm).attr("iti") != undefined) {
  11. var valid_data = ($(elm).children()[0]);
  12. var child_data = $(valid_data).children()[0];
  13. child_data = $(child_data).children()[0];
  14. var price_hooray_finally = $($(child_data).children()[0]).text();
  15. price_hooray_finally = price_hooray_finally.slice(1);
  16. var time = $($(valid_data).children()[2]);
  17. time = $(time).first().text().split(" ");
  18. var time_hours = (time[0] !== "from") ? time[0] : time[1];
  19. var time_minutes = (time[0] !== "from") ? time[1] : time[2];
  20. time = parseInt(time_hours.slice(0,-1)) + parseInt(time_minutes.slice(0,-1))/60;
  21. avg_price += parseInt(price_hooray_finally);
  22. avg_time += time;
  23. }
  24. });
  25.  
  26. avg_price = avg_price / flights.length;
  27. avg_time = avg_time / flights.length;
  28. console.log("Average Price: ", avg_price);
  29. console.log("Average Time: ", avg_time);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement