ah yeh - nice

thanks :)


On 22 May 2007, at 19:06, Jesse Graupmann wrote:

You have it, just decrease the i after any splice.



function removeArrayDuplicates ( array:Array )
{
        var a:Array = [].concat ( array );
        a.sort();

        for ( var i = 0; i < a.length; i++ )
        {
                if ( a[ i ] == a[ i + 1 ] ) a.splice ( --i + 1, 1 );
        }
        return a;
}


var array = [ 'a', 'a', 'b', 'c', 'a', 'b', 'b', 1, 5, 1, 2, 3, 1, 'AA',
'AA' ];

trace( 'array before: ' + array );

var arrayAFTER = removeArrayDuplicates ( array );

trace( 'array after: ' + arrayAFTER );



_____________________________

Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_____________________________


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Allandt
Bik-Elliott (Receptacle)
Sent: Tuesday, May 22, 2007 10:05 AM
To: flashcoders
Subject: [Flashcoders] remove duplicate items in array

hi guys

i'm looking for a way of removing duplicate items in an array

i've done this so far

//sort array so all items of the same content are grouped together
myArray.sort();

//loop through items, removing any sitting next to a duplicate
for (var i:Number = 0; i < myArray.length; i++) {
        if (myArray[i] == myArray[i+1]) {
                myArray.splice (i, 1);
        }
}

however, i always seems to end up with the first 2 items in the array
being the same (although it works well after that)

i can't figure out why - hope you can help

obie

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to