I have a little problem using jQuery and sorting a JSON array.
What I’m tring to do is to filter a geoJSON array depending on the hour selected by user.
The user can select a hours range using a jQuery slider.
$("#slider-range").slider({
stop: function(event, ui) {
$("#amount").val("h" + ui.values[0]+":00" +
"h" + ui.values[1]+":00");
minSel =ui.values[0];
maxSel =ui.values[1];
//HERE SHOULD BE PLACED THE FILTER FUNCTION
filterArray(minSel,maxSel);
}
});
How can can I return only the array values between the hour selection ordered by their visitedTimes?
Here below there’s a sample of the array.
Can anyone help me?
{ "type": "FeatureCollection", "features": [
{ "type": "Feature",
"id": "...",
"geometry": { "type": "Point", "coordinates": [...]},
"properties": { "venueName": "Its name",
"visitedTimes": "1",
"day": "07",
"month": "09",
"hour": "00",
"min": "50",
"sec": "58"
}
},
{ "type": "Feature",
"id": "4bd34eca462cb7133d1dde07",
"geometry": { "type": "Point", "coordinates": [...]},
"properties": { "venueName": "Old Wild West",
"visitedTimes": "4",
"day": "07",
"month": "09",
"hour": "00",
"min": "51",
"sec": "21"
}
},
{ "type": "Feature",
"id": "...",
"geometry": { "type": "Point", "coordinates": [...]},
"properties": { "venueName": "Past & future",
"day": "07",
"month": "09",
"hour": "00",
"min": "51",
"sec": "23"
}
}
]}
Use the jQuery.grep(array, function(elementOfArray, indexInArray) ) function to filter the array.
Then use the javascript sort function with a custom comparator function to sort by visitedTimes.