const SegmentCount = 2;
/* Given values that are dynamic later and only used for a sample here */
let Segment = 0;
let MaxStops_per_Segment = "2";
let MaxStop_Duration_per_Segment = "24:00";
let DepartureTime_Min = "09:00";
let DepartureTime_Max= "16:00";
let ArrivalTime_Min = "10:00";
let ArrivalTime_Max= "20:00";
/* All Fare data */
let Fares = [];
let SingleFare = [];
GenerateFareArray();
function GenerateFareArray() {
$(".singlefare .segment__moreFlightTimes input[type='radio']:checked").each(function() {
let currentSegment = $(this).attr("name").split("-");
SingleFare = {
FareID: $(this).closest(".singlefare").attr("id"),
Segment: currentSegment[1].slice(3,10),
StopAmount: $(this).data("stopamountsegment"),
DepartureTime: $(this).data("departuretimesegment"),
ArrivalTime: $(this).data("arrivaltimesegment")
};
Fares.push(SingleFare);
for (let i=0; i <= Object.keys(Fares).length; i++ ) {
console.log(SingleFare.FareID + " / Segment " + SingleFare.Segment + ": " + SingleFare.DepartureTime + " - " + SingleFare.ArrivalTime);
}
});
//NOW I NEED TO FILTER THE ARRAY SO THAT I GET THE NAMES (IDS) OF ALL MATCHING FARES
//FILTER THE COLLECTED (CHECKED) FARES AGAINST THE GIVEN SEGEMENT AND TIME VALUES (ROW 4-8)
FilterFares();
}
$(".segment__moreFlightTimes input[type='radio']").on("click", function() {
Fares = [];
GenerateFareArray();
});
function FilterFares() {
$(".singlefare").hide();
var matchingFares = $.grep(Fares, function(e) {
return e.Segment == Segment && e.StopAmount <= MaxStops_per_Segment && e.DepartureTime >= DepartureTime_Min && e.DepartureTime <= DepartureTime_Max && e.ArrivalTime >= ArrivalTime_Min && e.ArrivalTime <= ArrivalTime_Max;
});
console.log(matchingFares);
for(let f = 0; f<matchingFares.length; f++) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.