Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-27-2006, 09:06 PM   #1
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default dropping duplicate values in array?

is there a FAST way (fast meaning easy on proc) to drop duplicate values in an array?

lets say I have an array like...

[0, 0, 0, 0, 1, 1, 2, 6, 6, 6, 6, 8, 8 ]

and i want to simply return

[0, 1, 2, 6, 8]

is there a method for this already? i am having to do this with an array that is LARGE, like a few hundred values.. this is to help me with this problem here...

http://www.actionscript.org/forums/s....php3?t=122694

When I try this with LARGE arrays it is starting to take almost half a second each time... this is a problem since its for a game that has to be fast...

thanks for your help
apolloman is offline   Reply With Quote
Old 11-27-2006, 09:27 PM   #2
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default !!!

please help!
apolloman is offline   Reply With Quote
Old 11-27-2006, 10:03 PM   #3
EdKav1
Registered User
 
Join Date: Apr 2005
Location: Durham, NC
Posts: 305
Default

You can loop through your array once, using an associative array to track the values that have already been "seen" in your iteration. Something like
ActionScript Code:
function getUniqueValues(inArr:Array):Array{     var lookup:Array = new Array();     var uniqueArr:Array = new Array();     var num:Number     for(var idx:Number = 0; idx < inArr.length; idx++){         num = inArr[idx];         if(!lookup[num]){             uniqueArr.push(num);             lookup[num] = true;         }     }     return(uniqueArr); } var testArr:Array = [0, 0, 0, 0, 1, 1, 2, 6, 6, 6, 6, 8, 8 ]; var newArr:Array = getUniqueValues(testArr); trace("testArr is: " + testArr); trace("newArr is: " + newArr);

Ed
EdKav1 is offline   Reply With Quote
Old 11-27-2006, 10:15 PM   #4
dRees
Registered User
 
Join Date: May 2003
Posts: 24
Default

i've used this before and it's fast:

http://proto.layer51.com/d.aspx?f=1196
dRees is offline   Reply With Quote
Old 11-27-2006, 10:43 PM   #5
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default ...

awesome thanks!!
apolloman is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable that returns all values of an array guiltfilter ActionScript 2.0 4 12-12-2005 01:25 AM
checking for duplicate array values redrum ActionScript 2.0 0 11-28-2005 09:49 PM
how to store all the values in an array sbhar ActionScript 2.0 2 10-27-2005 02:45 PM
Access array values modified inside function tatemike44 ActionScript 1.0 (and below) 2 01-05-2005 07:12 PM
checking array for duplicate numbers malysmok ActionScript 1.0 (and below) 2 03-22-2004 11:00 AM


All times are GMT. The time now is 12:21 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.