I have a JSON with a say 10k records in it. Each record has a timestamp of the form ‘2011-04-29’.
Now I have a client side array (let’s call it our calendar) with arrays of the form –
['2011-04-26', '2011-05-02', 'Week 1', '2010 - 11']
...
The goal is to assign a week number to each record’s timestamp. I could use a classical linear search to accomplish this, but with 10k+ json records and close to 300 weeks in the calendar, this soon becomes tedious.
What would you recommend?
PS – I need the calendar because the weeks here are not the actual week of the year, but defined else where.
Would there be a more efficient way of doing this if i converted the strings to Date.getTime()?
With only 300 weeks, my approach would be to introduce an intermediate lookup object, matching each possible timestamp to the appropriate week. Just use a simple loop that will generate:
Those values would simply be indices in your
calendararray.Then you can assign your 10K of records to a calendar week with a simple lookup in this object.