<?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: ActionScript 3 Remove duplicates in an array</title>
	<atom:link href="http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/feed/" rel="self" type="application/rss+xml" />
	<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/</link>
	<description>Think Simple</description>
	<lastBuildDate>Wed, 07 Jul 2010 22:23:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mat G</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-641</link>
		<dc:creator>Mat G</dc:creator>
		<pubDate>Sun, 24 Jan 2010 22:55:31 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-641</guid>
		<description>Hi guys just though id throw a slightly different approach into the mix.. 

function removeDuplicates(array:Array):Array
{
	var tempRef:Dictionary = new Dictionary();
	var newArray:Array = [];
	var i:int = array.length;		
	var tempItem:*;
			
	while(i--)
	{
		tempItem = array[i]
			
		if(!tempRef[tempItem])
		{
			tempRef[tempItem] = true;
			newArray.push(tempItem);
		}
	}
			
	return newArray;
}</description>
		<content:encoded><![CDATA[<p>Hi guys just though id throw a slightly different approach into the mix.. </p>
<p>function removeDuplicates(array:Array):Array<br />
{<br />
	var tempRef:Dictionary = new Dictionary();<br />
	var newArray:Array = [];<br />
	var i:int = array.length;<br />
	var tempItem:*;</p>
<p>	while(i&#8211;)<br />
	{<br />
		tempItem = array[i]</p>
<p>		if(!tempRef[tempItem])<br />
		{<br />
			tempRef[tempItem] = true;<br />
			newArray.push(tempItem);<br />
		}<br />
	}</p>
<p>	return newArray;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Burke</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-640</link>
		<dc:creator>Martin Burke</dc:creator>
		<pubDate>Fri, 22 Jan 2010 15:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-640</guid>
		<description>I was having the same problem, where if I had something repeated more than once, only 1 got removed. This can simple be fixe dby replacing the &quot;if&quot; with a &quot;while&quot;. 

With an input of [&quot;a&quot;,&quot;a&quot;,&quot;b&quot;,&quot;b&quot;,&quot;c&quot;,&quot;c&quot;,&quot;a&quot;,&quot;a&quot;,&quot;d&quot;,&quot;d&quot;,&quot;e&quot;,&quot;e&quot;];

if (ac[i] === ac[j])
gives and output of &quot;a,b,c,a,d,e&quot; (wrong!)

while (ac[i] === ac[j])
gives an output of &quot;a,b,c,d,e&quot; (correct!)

The while forces a check on the new element which has shifted into the position which has just been deleted</description>
		<content:encoded><![CDATA[<p>I was having the same problem, where if I had something repeated more than once, only 1 got removed. This can simple be fixe dby replacing the &#8220;if&#8221; with a &#8220;while&#8221;. </p>
<p>With an input of ["a","a","b","b","c","c","a","a","d","d","e","e"];</p>
<p>if (ac[i] === ac[j])<br />
gives and output of &#8220;a,b,c,a,d,e&#8221; (wrong!)</p>
<p>while (ac[i] === ac[j])<br />
gives an output of &#8220;a,b,c,d,e&#8221; (correct!)</p>
<p>The while forces a check on the new element which has shifted into the position which has just been deleted</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthieu Chavigny</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-631</link>
		<dc:creator>Matthieu Chavigny</dc:creator>
		<pubDate>Thu, 17 Dec 2009 14:53:17 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-631</guid>
		<description>public static function unique(a:Array):Array
{
	var n:Array = new Array();
	for each(var e in a) {
		var o:Boolean = false;
		for each(var ne in n) if (ne == e) o=true;
		if(!o) n.push(e);
	}
	return n;
}</description>
		<content:encoded><![CDATA[<p>public static function unique(a:Array):Array<br />
{<br />
	var n:Array = new Array();<br />
	for each(var e in a) {<br />
		var o:Boolean = false;<br />
		for each(var ne in n) if (ne == e) o=true;<br />
		if(!o) n.push(e);<br />
	}<br />
	return n;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruno Fenzl</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-552</link>
		<dc:creator>Bruno Fenzl</dc:creator>
		<pubDate>Sun, 25 Oct 2009 20:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-552</guid>
		<description>@Brian
your code is simple and very efficient. Great!!!! thanks.

@all
Thanks for the wonderful examples of logic.</description>
		<content:encoded><![CDATA[<p>@Brian<br />
your code is simple and very efficient. Great!!!! thanks.</p>
<p>@all<br />
Thanks for the wonderful examples of logic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-150</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Tue, 21 Jul 2009 07:06:02 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-150</guid>
		<description>This is the version I just made up:

array.forEach( removeDups );
function removeDups( value:*, index:int, arr:Array):void {
	for( var i:Number = 0; i &lt; arr.length; i++ ) if( i != index ) if( value === arr[i] ) arr.splice( i, 1 );
}</description>
		<content:encoded><![CDATA[<p>This is the version I just made up:</p>
<p>array.forEach( removeDups );<br />
function removeDups( value:*, index:int, arr:Array):void {<br />
	for( var i:Number = 0; i &lt; arr.length; i++ ) if( i != index ) if( value === arr[i] ) arr.splice( i, 1 );<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xavier Laumonier</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-148</link>
		<dc:creator>Xavier Laumonier</dc:creator>
		<pubDate>Wed, 03 Jun 2009 08:48:07 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-148</guid>
		<description>Hi !

Good function, but it should be :

    var length:int = ac.length
    for (i = 0; i &lt; length - 1; i++)
        for (j = i + 1; j &lt; length ; j++)

it will be much more optimized, because the length of the array is computed one time in this version, but in your version, the length of the array is computed ( 2 * array.length - 1 ) times..</description>
		<content:encoded><![CDATA[<p>Hi !</p>
<p>Good function, but it should be :</p>
<p>    var length:int = ac.length<br />
    for (i = 0; i &lt; length &#8211; 1; i++)<br />
        for (j = i + 1; j &lt; length ; j++)</p>
<p>it will be much more optimized, because the length of the array is computed one time in this version, but in your version, the length of the array is computed ( 2 * array.length &#8211; 1 ) times..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bubbleboy</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-149</link>
		<dc:creator>bubbleboy</dc:creator>
		<pubDate>Thu, 14 May 2009 19:09:47 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-149</guid>
		<description>just what i was looking for! thanks a lot!</description>
		<content:encoded><![CDATA[<p>just what i was looking for! thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trickmaster</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-147</link>
		<dc:creator>Trickmaster</dc:creator>
		<pubDate>Tue, 24 Mar 2009 20:43:25 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-147</guid>
		<description>Hey thanks a bunch! i tried this code yesterday didn&#039;t work since I had 4 same values in my array, and it only got rid of 2 of them. Then I looked at Quince&#039;s comment today and I retried the code and it worked like a charm!

Thanks a bunch man</description>
		<content:encoded><![CDATA[<p>Hey thanks a bunch! i tried this code yesterday didn&#8217;t work since I had 4 same values in my array, and it only got rid of 2 of them. Then I looked at Quince&#8217;s comment today and I retried the code and it worked like a charm!</p>
<p>Thanks a bunch man</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mauro</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-146</link>
		<dc:creator>mauro</dc:creator>
		<pubDate>Sun, 04 Jan 2009 14:43:01 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-146</guid>
		<description>Sorry guys, I am interested in using this code, but which one is best for checking duplicates in matter of emails?

The array to be a list of emails.

I have done a script(*) to get rid of almost every dirt from copy and paste from CSV, XLS, Outlook, and other common tools.

Now I would like to get rid of duplicates!

(*)Here is the source code:
http://www.vacanzecroate.com/careless/email/ciclo_CommaEmails_fromTAB.html</description>
		<content:encoded><![CDATA[<p>Sorry guys, I am interested in using this code, but which one is best for checking duplicates in matter of emails?</p>
<p>The array to be a list of emails.</p>
<p>I have done a script(*) to get rid of almost every dirt from copy and paste from CSV, XLS, Outlook, and other common tools.</p>
<p>Now I would like to get rid of duplicates!</p>
<p>(*)Here is the source code:<br />
<a href="http://www.vacanzecroate.com/careless/email/ciclo_CommaEmails_fromTAB.html" rel="nofollow">http://www.vacanzecroate.com/careless/email/ciclo_CommaEmails_fromTAB.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://simplistika.com/actionscript-3-remove-duplicates-in-an-array/comment-page-1/#comment-145</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Fri, 24 Oct 2008 23:40:49 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=33#comment-145</guid>
		<description>don&#039;t forget closures in as 3.

var is_unique:Function = function (item:*, index:int, array:Array):Boolean {
		 return array.indexOf(item,index + 1) == -1;
};

var array = [1,2,1,3,2,3];
trace(array.filter(is_unique));</description>
		<content:encoded><![CDATA[<p>don&#8217;t forget closures in as 3.</p>
<p>var is_unique:Function = function (item:*, index:int, array:Array):Boolean {<br />
		 return array.indexOf(item,index + 1) == -1;<br />
};</p>
<p>var array = [1,2,1,3,2,3];<br />
trace(array.filter(is_unique));</p>
]]></content:encoded>
	</item>
</channel>
</rss>
