Doug and Gordon, thanks for the advise. I decided on the following solution.
public function populateStatusArray(array:Array):void { var newArrayHashMap : Object = new Object(); var status : Array = new Array; status.push("All"); var n:int = array.length; for (var i:int = 0; i < n; i++) { if (newArrayHashMap[array[i].status] == undefined) { newArrayHashMap[array[i].status] = new Object(); status.push(array[i].status); } } status.sort(); ModelLocator.getInstance().statusArray = status; } Tim Hoff --- In flexcoders@yahoogroups.com, "Gordon Smith" <[EMAIL PROTECTED]> wrote: > > You can use a plain Object as a Set... see the code below. > > You first put key/value pairs into the Object, but it makes no > difference what the values are. You just care about the keys, and the > Object's hash table takes care of ensuring that setting a key more than > once is harmless. > > Then you iterate over the Object, pulling out the unique keys into an > Array that can be sorted. > > Finally, you stick "All" at the top, after the sort. > > - Gordon > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="600" > height="600"> > > <mx:Script> > <![CDATA[ > > [Bindable] > private var array:Array = [ "B", "C", "A", "B", "A", "D" > ]; > > public function getUniqueItems(array:Array):Array > { > var uniqueItemHash:Object = {}; > var n:int = array.length; > for (var i:int = 0; i < n; i++) > { > uniqueItemHash[array[i]] = true; > } > > var uniqueItemArray:Array = []; > for (var p:String in uniqueItemHash) > { > uniqueItemArray.push(p); > } > > uniqueItemArray.sort(); > uniqueItemArray.unshift("All"); > return uniqueItemArray; > } > > ]]> > </mx:Script> > > <mx:ComboBox dataProvider="{getUniqueItems(array)}"/> > > </mx:Application> > > -----Original Message----- > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of Doug Lowder > Sent: Tuesday, April 11, 2006 5:00 PM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Re: AS3 Array Question > > For large arrays, it will be more efficient to do this: > > 1) Make a copy of the input array, if necessary > 2) Sort the array by status > 3) Iterate through the array once, storing new status values and > skipping the duplicates > > > --- In flexcoders@yahoogroups.com, "turbo_vb" <TimHoff@> wrote: > > > > I'm trying to populate a dataProvider array for a comboBox that > > contains unique status values from another array, that is used as > > the dataProvider for a dataGrid. The comboBox is used to filter > the > > dataGrid. The code below works, but I seem to remember seeing > this > > done somewhere that doesn't use nested for statements. Does > anyone > > know how I can identify if the array's status value already exists > > in the new status array without iterating the new array every time? > > > > public function populateStatusArray(array:Array):void { > > > > var status : Array = new Array; > > status.push("All"); > > > > var n:int = citations.length; > > for (var i:int = 0; i < n; i++) { > > var m:int = status.length; > > var found:Boolean = false; > > for (var j:int = 0; j < m; j++) { > > if (status[j] == array[i].status){ > > found = true; > > } > > } > > if (found == false) { > > status.push(array[i].status); > > } > > } > > status.sort(); > > ModelLocator.getInstance().statusArray = > status; > > } > > > > Thank You, > > Tim Hoff > > > > > > > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/