<?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: Javascript: Remove duplicates from Array</title>
	<atom:link href="http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html</link>
	<description>Logic to Art</description>
	<lastBuildDate>Fri, 06 Aug 2010 03:43:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Alex</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-6411</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Wed, 21 Jul 2010 13:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-6411</guid>
		<description>There is an alternative example here at:
http://www.bytechaser.com/en/functions/xjfj6grjfr/create-a-distinct-list-from-a-javascript-array.aspx 
which works with text and numbers and allows you to specify if you want the process to be case sensitive.</description>
		<content:encoded><![CDATA[<p>There is an alternative example here at:<br />
<a href="http://www.bytechaser.com/en/functions/xjfj6grjfr/create-a-distinct-list-from-a-javascript-array.aspx" rel="nofollow">http://www.bytechaser.com/en/functions/xjfj6grjfr/create-a-distinct-list-from-a-javascript-array.aspx</a><br />
which works with text and numbers and allows you to specify if you want the process to be case sensitive.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajini</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-6331</link>
		<dc:creator>Rajini</dc:creator>
		<pubDate>Mon, 12 Jul 2010 21:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-6331</guid>
		<description>Fantastic! It saved my time a lot.
Keep it up!</description>
		<content:encoded><![CDATA[<p>Fantastic! It saved my time a lot.<br />
Keep it up!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: getburl</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-6144</link>
		<dc:creator>getburl</dc:creator>
		<pubDate>Thu, 17 Jun 2010 15:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-6144</guid>
		<description>Here is a slightly different approach. Rather than grabbing on the matches, I grabbed where in the sequence when they do not match after sorting.

var dedup = function(a)
	{
		a.sort(); //get the dups together
		var b = []; //create a replacement array
		for(var i=a.length;i--;) //loop down the original array
			{
				if(a[i]!==a[i-1]) //since they are bunched, only pull out the ones that don&#039;t match
					{
						b[b.length] = a[i]; // give the replacement array the ones that dont match
					}
			}
		return b; // return the replacement arra
	}
alert(&#039;Original Array:\&#039;bob\&#039;,\&#039;sally\&#039;,9,\&#039;sally\&#039;,\&#039;george\&#039;,\&#039;george \&#039;,\&#039;andrew\&#039;,23,230,\&#039;23\&#039;\n&#039; + &#039;Deduped Array:&#039;+ dedup([&#039;bob&#039;,&#039;sally&#039;,9,&#039;sally&#039;,&#039;george&#039;,&#039;george &#039;,&#039;andrew&#039;,23,230,&#039;23&#039;]));</description>
		<content:encoded><![CDATA[<p>Here is a slightly different approach. Rather than grabbing on the matches, I grabbed where in the sequence when they do not match after sorting.</p>
<p>var dedup = function(a)<br />
	{<br />
		a.sort(); //get the dups together<br />
		var b = []; //create a replacement array<br />
		for(var i=a.length;i&#8211;;) //loop down the original array<br />
			{<br />
				if(a[i]!==a[i-1]) //since they are bunched, only pull out the ones that don&#8217;t match<br />
					{<br />
						b[b.length] = a[i]; // give the replacement array the ones that dont match<br />
					}<br />
			}<br />
		return b; // return the replacement arra<br />
	}<br />
alert(&#8216;Original Array:\&#8217;bob\&#8217;,\&#8217;sally\&#8217;,9,\&#8217;sally\&#8217;,\&#8217;george\&#8217;,\&#8217;george \&#8217;,\&#8217;andrew\&#8217;,23,230,\&#8217;23\&#8217;\n&#8217; + &#8216;Deduped Array:&#8217;+ dedup(['bob','sally',9,'sally','george','george ','andrew',23,230,'23']));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jose</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-6069</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Thu, 10 Jun 2010 08:42:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-6069</guid>
		<description>@vakata  Thanks you very much!</description>
		<content:encoded><![CDATA[<p>@vakata  Thanks you very much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mason Houtz</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-5924</link>
		<dc:creator>Mason Houtz</dc:creator>
		<pubDate>Thu, 27 May 2010 01:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-5924</guid>
		<description>@Martin

I&#039;m definitely not suggesting it&#039;s a good idea to misuse an array by treating it like an associative hash. What I&#039;m suggesting is that others have nonetheless already done so, and my point was that this kind of thing can break existing code.

I know better, man. :)</description>
		<content:encoded><![CDATA[<p>@Martin</p>
<p>I&#8217;m definitely not suggesting it&#8217;s a good idea to misuse an array by treating it like an associative hash. What I&#8217;m suggesting is that others have nonetheless already done so, and my point was that this kind of thing can break existing code.</p>
<p>I know better, man. <img src='http://www.martienus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: csodar</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-5529</link>
		<dc:creator>csodar</dc:creator>
		<pubDate>Tue, 20 Apr 2010 19:50:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-5529</guid>
		<description>A file of mine has a virus and i don&#039;t want to delete it how can I erase the virus from existence and still keep my file? If you have the name of a comp program that can do it please do tell. 


_____________
&lt;a href=&quot;http://www.youtube.com/watch?v=t1mpT1-uTu4&quot; rel=&quot;nofollow&quot;&gt;grow taller&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>A file of mine has a virus and i don&#8217;t want to delete it how can I erase the virus from existence and still keep my file? If you have the name of a comp program that can do it please do tell. </p>
<p>_____________<br />
<a href="http://www.youtube.com/watch?v=t1mpT1-uTu4" rel="nofollow">grow taller</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vakata</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-5037</link>
		<dc:creator>vakata</dc:creator>
		<pubDate>Tue, 09 Mar 2010 13:28:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-5037</guid>
		<description>Just came up with this one-liner:

a = a.sort().join(&quot;,,&quot;).replace(/(,&#124;^)([^,]+)(,,\2)+(,&#124;$)/g,&quot;$1$2$4&quot;).replace(/,,+/g,&quot;,&quot;).replace(/,$/,&quot;&quot;).split(&quot;,&quot;);

NOTE:
1) Choose delimiter carefully (this example uses &quot;,&quot;)
2) Returned array is sorted!
3) Returned array is an array of strings

Cheers,
Ivan</description>
		<content:encoded><![CDATA[<p>Just came up with this one-liner:</p>
<p>a = a.sort().join(&#8220;,,&#8221;).replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,&#8221;$1$2$4&#8243;).replace(/,,+/g,&#8221;,&#8221;).replace(/,$/,&#8221;").split(&#8220;,&#8221;);</p>
<p>NOTE:<br />
1) Choose delimiter carefully (this example uses &#8220;,&#8221;)<br />
2) Returned array is sorted!<br />
3) Returned array is an array of strings</p>
<p>Cheers,<br />
Ivan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: claudio</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-4897</link>
		<dc:creator>claudio</dc:creator>
		<pubDate>Sat, 27 Feb 2010 00:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-4897</guid>
		<description>I really appreciate it. Over so many solutions your worked.</description>
		<content:encoded><![CDATA[<p>I really appreciate it. Over so many solutions your worked.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-4649</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Tue, 09 Feb 2010 02:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-4649</guid>
		<description>Back to Mason Houtz way up in the response list: check out http://www.kenegozi.com/blog/2009/04/13/javascript-and-the-extended-array-prototype.aspx to prove you wrong at the destructive side of array prototyping. When functionalities collide, always go back to the original intention behind it :)
If though approaching arrays in an associative manner is imperative in your system, prototyping array functionality will indeed prove destructive.</description>
		<content:encoded><![CDATA[<p>Back to Mason Houtz way up in the response list: check out <a href="http://www.kenegozi.com/blog/2009/04/13/javascript-and-the-extended-array-prototype.aspx" rel="nofollow">http://www.kenegozi.com/blog/2009/04/13/javascript-and-the-extended-array-prototype.aspx</a> to prove you wrong at the destructive side of array prototyping. When functionalities collide, always go back to the original intention behind it <img src='http://www.martienus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
If though approaching arrays in an associative manner is imperative in your system, prototyping array functionality will indeed prove destructive.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shanti</title>
		<link>http://www.martienus.com/code/javascript-remove-duplicates-from-array.html/comment-page-1#comment-4122</link>
		<dc:creator>Shanti</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.martienus.com/code/javascript-remove-duplicates-from-array.html#comment-4122</guid>
		<description>With JavaScript 1.7, you can do this

Array.prototype.unique = function () 
{
    var r = new Array();
    for(var i = 0, n = this.length; i &lt; n; i++)
    {
        if (this.lastIndexOf(this[i]) == i) r.push(this[i]);
    }
    return r;
}</description>
		<content:encoded><![CDATA[<p>With JavaScript 1.7, you can do this</p>
<p>Array.prototype.unique = function ()<br />
{<br />
    var r = new Array();<br />
    for(var i = 0, n = this.length; i &lt; n; i++)<br />
    {<br />
        if (this.lastIndexOf(this[i]) == i) r.push(this[i]);<br />
    }<br />
    return r;<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 3.139 seconds -->
