views:

65

answers:

1

I have an array with lots of items with same names like

 CloudObserverCMSStub edited 
 CloudObserverCMSStub edited 
 CloudObserverCMSStub created 
 CloudObserverCMSStub2 edited 
 CloudObserverCMSStub2 edited 
 CloudObserverCMSStub2 created

and different related to names dates for each item in such format

Wed, 17 Mar 2010 22:32:09 GMT
Wed, 17 Mar 2010 22:32:07 GMT
Wed, 17 Mar 2010 22:32:02 GMT
Wed, 17 Mar 2010 22:31:02 GMT
Wed, 17 Mar 2010 21:32:02 GMT
Wed, 15 Mar 2009 22:32:02 GMT

I want to sort them so that I get only the latest ones in such format (with no such stuff like edited or created)

CloudObserverCMSStub   |    Wed, 17 Mar 2010 22:32:09 GMT
CloudObserverCMSStub2  |    Wed, 17 Mar 2010 22:31:02 GMT

So I want a new array of 2 items from for example 6 how to do such thing?

A: 

You create an object, store the common names as the keys, and use dates as values. Then you can compare the dates and replace it if the date is more recent. Eg:

var obj:Object;

for(var element in array)  // I honestly forget AS3 syntax.
{
    if(obj[element.name] == null)
    {
        obj[element.name] = element;
    }
    else
    {
        if(obj[element.name].date > element.date)
        {
            obj[element.name] = element;
        }
    }
}

Then just enumerate all the elements in obj.

CookieOfFortune
The problem is - I have names in DB "CloudObserverCMSStub created" and "CloudObserverCMSStub edited" your code is grate - working. But it gives me bouth created and edited ones. So next Question is how to get rid of all object items with names started with something and ended with created (If edited exists). Do you know how to do such thing?
Blender
Well, if you take what I've written already, enter in your condition for replacement in the second if statement.
CookieOfFortune