5 Replies Latest reply on Dec 13, 2008 7:26 PM by Newsgroup_User

# Without looping: Determine number of unique values in a set

Hi all,
I was wondering if anyone has any advice on determining the number of unique items in a set. For example:

If I have an ArrayCollection
public var someData:ArrayCollection = new ArrayCollection([
{id:"1", color:"Red", value:5"},
{id:"2", color:"Red", value:"4"},
{id:"3", color:"Green", value:"17"},
{id:"4", color:"Red", value:"3"},
{id:"5", color:"Blue", value:"4"}]);

What I want returned is just Red, Green, Blue but not Red, Red, Green, Red, Blue. Or even better would just be a number telling me how many unique values are in the set. I've spent hours digging through the asdocs but have not found anything that performs this type of analysis and I've typically had to resort to endless loops (which can affect performance when the data set is large).

I would appreciate any words of wisdom.
• ###### 1. Re: Without looping: Determine number of unique values in a set
Well, you can not really know what you have at all without looping of some sort. ;-)

Here is a thread with a post of mine that might help you:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid =1404229&highlight_key=y&keyword1=filter

• ###### 2. Re: Without looping: Determine number of unique values in a set
I haven't tried this solution, but let me know if it helps you.
http://www.badu.ro/?p=11
• ###### 3. Re: Without looping: Determine number of unique values in a set

"shawn.yale" <syale@triad.rr.com> wrote in message
news:ghs5lo\$fkb\$1@forums.macromedia.com...
> Hi all,
> I was wondering if anyone has any advice on determining the number of
> unique
> items in a set. For example:
>
> If I have an ArrayCollection
> public var someData:ArrayCollection = new ArrayCollection([
> {id="1", color="Red", value="5"},
> {id="2", color="Red", value="4"},
> {id="3", color="Green", value="17"},
> {id="4", color="Red", value="3"},
> {id="5", color="Blue", value="4"}]);
>
> What I want returned is just Red, Green, Blue but not Red, Red,
> Green,
> Red, Blue. Or even better would just be a number telling me how many
> unique
> values are in the set. I've spent hours digging through the asdocs but
> have
> not found anything that performs this type of analysis and I've typically
> had
> to resort to endless loops (which can affect performance when the data set
> is
> large).
>
> I would appreciate any words of wisdom.

You could use a GroupingCollection with a SummaryRow.

HTH;

Amy

• ###### 4. Without looping: Determine number of unique values in a set
Thanks Amy et al. Cheers I owe you all a beer. Good starting point. Does anyone know of a realistic example of using grouping collections and summary rows?
• ###### 5. Re: Without looping: Determine number of unique values in a set

"shawn.yale" <syale@triad.rr.com> wrote in message
news:gi1kh8\$fko\$1@forums.macromedia.com...
> Thanks Amy. Cheers I owe you a beer.

You're welcome :-).

I prefer amber to dark :-p