<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Find all unique values from array or collection</title>
	<atom:link href="http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/feed/" rel="self" type="application/rss+xml" />
	<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/</link>
	<description>Flex with a hint of cool</description>
	<lastBuildDate>Thu, 08 Sep 2011 08:01:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
	<item>
		<title>By: harishvardhan</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-3379</link>
		<dc:creator>harishvardhan</dc:creator>
		<pubDate>Thu, 21 Oct 2010 12:37:22 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-3379</guid>
		<description>i have a arraycollection in which each element is a dictionary
for ex: Item 1: Fontstyle:Italic
1:46 item 2:Fontstyle :bold
item3:Underline :true
in this array collection i want to remove the fontstyle attributed items and add it to a new dictionary where in it contains only the unique values

how to do this?

can you email me please?harishvardhan@ymail.com</description>
		<content:encoded><![CDATA[<p>i have a arraycollection in which each element is a dictionary<br />
for ex: Item 1: Fontstyle:Italic<br />
1:46 item 2:Fontstyle :bold<br />
item3:Underline :true<br />
in this array collection i want to remove the fontstyle attributed items and add it to a new dictionary where in it contains only the unique values</p>
<p>how to do this?</p>
<p>can you email me please?harishvardhan@ymail.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Bishop</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-2549</link>
		<dc:creator>Brian Bishop</dc:creator>
		<pubDate>Tue, 15 Jun 2010 09:59:49 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-2549</guid>
		<description>Hi 

Nice post. Heres a helpful addition to the function that I needed. If you have an array of objects (any type of objects), you can pass in which property of the objects you wish to target.

&lt;code&gt;
/**
        * Get the unique values stored within an arrayCollection
        * 
        * @param The arrayCollection to search
        * @param The property value of the arrayCollection&#039;s objects to target
        * @return an arrayCollection of unique items;
        */
		public function getUniqueValues (collection:ArrayCollection, propertyName:String):ArrayCollection {
			
			var length:Number = collection.length;
			var dict:Dictionary = new Dictionary();
					 
			//this should be whatever type of object you have inside your AC
			var obj:Object;
			for(var i:int = 0; i &lt; length; i++){
				obj = collection.getItemAt(i);
				
				dict[obj[propertyName]] = obj[propertyName];
			}
		 
			//this bit goes through the dictionary and puts data into a new AC
		    var unique:ArrayCollection = new ArrayCollection();
		    for(var propertyString:String in dict){
		    	unique.addItem(dict[propertyString]);
		    }
		    return unique;
		}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi </p>
<p>Nice post. Heres a helpful addition to the function that I needed. If you have an array of objects (any type of objects), you can pass in which property of the objects you wish to target.</p>
<p><code><br />
/**<br />
        * Get the unique values stored within an arrayCollection<br />
        *<br />
        * @param The arrayCollection to search<br />
        * @param The property value of the arrayCollection's objects to target<br />
        * @return an arrayCollection of unique items;<br />
        */<br />
		public function getUniqueValues (collection:ArrayCollection, propertyName:String):ArrayCollection {</p>
<p>			var length:Number = collection.length;<br />
			var dict:Dictionary = new Dictionary();</p>
<p>			//this should be whatever type of object you have inside your AC<br />
			var obj:Object;<br />
			for(var i:int = 0; i &lt; length; i++){<br />
				obj = collection.getItemAt(i);</p>
<p>				dict[obj[propertyName]] = obj[propertyName];<br />
			}</p>
<p>			//this bit goes through the dictionary and puts data into a new AC<br />
		    var unique:ArrayCollection = new ArrayCollection();<br />
		    for(var propertyString:String in dict){<br />
		    	unique.addItem(dict[propertyString]);<br />
		    }<br />
		    return unique;<br />
		}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenneth</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-1695</link>
		<dc:creator>Kenneth</dc:creator>
		<pubDate>Tue, 23 Feb 2010 23:39:32 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-1695</guid>
		<description>As long as you remember the following when using the keys then it works fine and is much quicker than a double loop.  
The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison. When an object is used as a key, the object&#039;s identity is used to look up the object, and not the value returned from calling toString() on it. Primitive (built-in) objects, like Numbers, in a Dictionary collection behave in the same manner as they do when they are the property of a regular object.</description>
		<content:encoded><![CDATA[<p>As long as you remember the following when using the keys then it works fine and is much quicker than a double loop.<br />
The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison. When an object is used as a key, the object&#8217;s identity is used to look up the object, and not the value returned from calling toString() on it. Primitive (built-in) objects, like Numbers, in a Dictionary collection behave in the same manner as they do when they are the property of a regular object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bendy</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-1693</link>
		<dc:creator>Bendy</dc:creator>
		<pubDate>Tue, 23 Feb 2010 08:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-1693</guid>
		<description>I do believe the dictionary hash uses AS3&#039;s built-in &quot;equality&quot;: comparing by reference. You only get unique objects by reference.

If you want unique objects by equality, you should use ObjectUtil.compare and a double loop, checking each item against the unique items found so far. This is something like O(n^2).</description>
		<content:encoded><![CDATA[<p>I do believe the dictionary hash uses AS3&#8242;s built-in &#8220;equality&#8221;: comparing by reference. You only get unique objects by reference.</p>
<p>If you want unique objects by equality, you should use ObjectUtil.compare and a double loop, checking each item against the unique items found so far. This is something like O(n^2).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suma Gowda</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-1527</link>
		<dc:creator>Suma Gowda</dc:creator>
		<pubDate>Fri, 29 Jan 2010 22:42:33 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-1527</guid>
		<description>Thank You :-)</description>
		<content:encoded><![CDATA[<p>Thank You <img src='http://kennethsutherland.com/wordpress1/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VANESSA</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-1494</link>
		<dc:creator>VANESSA</dc:creator>
		<pubDate>Fri, 22 Jan 2010 13:38:52 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-1494</guid>
		<description>thanks for this code. It will definitely be useful innumberable times for me... 
Good job and keep blogging...</description>
		<content:encoded><![CDATA[<p>thanks for this code. It will definitely be useful innumberable times for me&#8230;<br />
Good job and keep blogging&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Lyles</title>
		<link>http://kennethsutherland.com/2009/04/02/find-all-unique-values-from-array-or-collection/comment-page-1/#comment-12</link>
		<dc:creator>Chris Lyles</dc:creator>
		<pubDate>Thu, 07 May 2009 19:06:47 +0000</pubDate>
		<guid isPermaLink="false">http://kennethsutherland.com/?p=74#comment-12</guid>
		<description>Thanks for taking the time to publish your handy work...it&#039;s been very helpful.</description>
		<content:encoded><![CDATA[<p>Thanks for taking the time to publish your handy work&#8230;it&#8217;s been very helpful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

