If your collection is sorted by timestamp a binary search would be faster.
--- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> You'll have to loop through yourself and keep track of the minimum
> difference
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of blc187
> Sent: Wednesday, August 13, 2008 12:57 PM
> To: [email protected]
> Subject: [flexcoders] how to search an arraycollection
>
>
>
> I have an arraycollection of objects, each of which has a timestamp.
> ex: {timestamp:4342423432, value:5}
>
> I want to search the arraycollection for the object which has the
> closest timestamp to the time I'm looking for.
> Is there a way to search the arraycollection for an approximate value?
>
> As of right now I'm looping through each object in my arraycollection
> to find if the value is between 2 numbers.
>
> for(var i:int = 0; i < dataProvider.length; i++) {
> if(myTimestamp > dataProvider[i] && myTimestamp < dataProvider[i+1])
> //this is the correct spot.
> }
>