Is there anyone who can assist me with an algorithm? I have a list of events and need to retrieve the next event and previous events based on the current date.
For example:
I fetch all events from an SQL database like so:
events = [
{eventId:1, eventDate: "Wen Apr 01 2015 18:41:00 GMT+0300", eventPlace:"Dortmund, DE"},
{eventId:2, eventDate: "Sun Apr 05 2015 23:41:00 GMT+0300", eventPlace:"Budapest, HU"},
{eventId:3, eventDate: "Fri Apr 03 2015 13:41:00 GMT+0300", eventPlace:"Madrid, ES"},
{eventId:4, eventDate: "Mon Jun 01 2015 22:00:00 GMT+0300", eventPlace:"London, EN"},
.......
{eventId:100, eventDate: "Mon Aug 31 2015 22:00:00 GMT+0300"}
]
If the current date is Sun Apr 05 2015 15:00:00, I would like to obtain:
resultNextEv= {eventId:2, eventDate: "Sun Apr 05 2015 23:41:00 GMT+0300", eventPlace:"Budapest, HU"}
resultLastEv= {eventId:3, eventDate: "Fri Apr 03 2015 13:41:00 GMT+0300", eventPlace:"Madrid, ES"}
What is the most efficient way to achieve this result? (I am using JavaScript / Angular) Any suggestions or ideas?
Thank you