<?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: Deduplicate any array in Javascript</title>
	<atom:link href="http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/</link>
	<description>Nothing is impossible.  Even on the Web.</description>
	<lastBuildDate>Mon, 28 Jun 2010 22:12:59 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-818</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Fri, 18 Dec 2009 14:43:56 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-818</guid>
		<description>Is it &quot;just a little faster&quot; because the variable, &lt;code&gt;ary&lt;/code&gt;, is lower in the scope chain than &lt;code&gt;array&lt;/code&gt;? Or is there some special magic here?</description>
		<content:encoded><![CDATA[<p>Is it &#8220;just a little faster&#8221; because the variable, <code>ary</code>, is lower in the scope chain than <code>array</code>? Or is there some special magic here?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fearphage</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-813</link>
		<dc:creator>fearphage</dc:creator>
		<pubDate>Sat, 12 Dec 2009 11:59:49 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-813</guid>
		<description>It can actually be just a little faster than that using the third parameter:
&lt;pre lang=&quot;javascript&quot;&gt;array.filter(function(item, i, ary) {
  return ary.indexOf(item) == i;
});&lt;/pre&gt;

(Corrected the variable names)</description>
		<content:encoded><![CDATA[<p>It can actually be just a little faster than that using the third parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">array.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> ary<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> ary.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(Corrected the variable names)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fearphage</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-812</link>
		<dc:creator>fearphage</dc:creator>
		<pubDate>Sat, 12 Dec 2009 11:58:40 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-812</guid>
		<description>It can actually be just a little faster than that using the third parameter::
&lt;pre lang=&quot;javascript&quot;&gt;array.filter(function(value, i, ary) {
  return ary.indexOf(item) == i;
});&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>It can actually be just a little faster than that using the third parameter::</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">array.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> ary<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> ary.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: fearphage</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-809</link>
		<dc:creator>fearphage</dc:creator>
		<pubDate>Wed, 09 Dec 2009 17:05:13 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-809</guid>
		<description>Why not use the native filter for primitives?

&lt;pre lang=&quot;javascript&quot;&gt;array.filter(function(item, i) {
  return array.indexOf(item) == i;
});&lt;/pre&gt;

I understand this won&#039;t work for complex objects and if you want them sorted, you&#039;ll have to do that afterwards.</description>
		<content:encoded><![CDATA[<p>Why not use the native filter for primitives?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">array.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> array.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I understand this won&#8217;t work for complex objects and if you want them sorted, you&#8217;ll have to do that afterwards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-808</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Tue, 08 Dec 2009 23:58:39 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-808</guid>
		<description>indexOf is unfortunately expensive only in IE where it&#039;s not native while splice could be expensive but above for loop is something extremely easy to maintain (5 line of code that should just work).
On the other hand I am using on up to two native methods against sort + forEach + map + push + all callbacks involved and executed for each index so I am kinda sure mine will perform 2 up to 5 times faster (in IE as example just sort is expensive).
Finally, if the goal is to make something portable for every case, objects included, with mine you are sure about unique primitives/instances so it depends what you need (if you need just to compare a single object property, mine won&#039;t make sense)
Regards</description>
		<content:encoded><![CDATA[<p>indexOf is unfortunately expensive only in IE where it&#8217;s not native while splice could be expensive but above for loop is something extremely easy to maintain (5 line of code that should just work).<br />
On the other hand I am using on up to two native methods against sort + forEach + map + push + all callbacks involved and executed for each index so I am kinda sure mine will perform 2 up to 5 times faster (in IE as example just sort is expensive).<br />
Finally, if the goal is to make something portable for every case, objects included, with mine you are sure about unique primitives/instances so it depends what you need (if you need just to compare a single object property, mine won&#8217;t make sense)<br />
Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-807</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Tue, 08 Dec 2009 22:40:02 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-807</guid>
		<description>Interesting! I wouldn&#039;t have thought to use indexOf() or splice() since I just assumed those were expensive operations.  I see you&#039;ve minimized the impact of scanning the array by using the second argument for indexOf().  Clever.  Some day I&#039;ll do some real benchmarking to see what works best.</description>
		<content:encoded><![CDATA[<p>Interesting! I wouldn&#8217;t have thought to use indexOf() or splice() since I just assumed those were expensive operations.  I see you&#8217;ve minimized the impact of scanning the array by using the second argument for indexOf().  Clever.  Some day I&#8217;ll do some real benchmarking to see what works best.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-806</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Tue, 08 Dec 2009 20:32:56 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-806</guid>
		<description>I know there is not compare function, but was not this good enough?
&lt;pre lang=&quot;javascript&quot;&gt;
for(var i = 1, length = array.length, n; i &lt; length; ++i){
    if(-1 &lt; (n = array.indexOf(array[i - 1], i))){
        a.splice(n, 1);
        --length;
        --i;
    }
};
&lt;/pre&gt;
an optimized fast performances version could avoid the inline splice and store those index to discard (splice could cost a lot) in order to push only certain indexes (not duplicated)</description>
		<content:encoded><![CDATA[<p>I know there is not compare function, but was not this good enough?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> length <span style="color: #339933;">=</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> n<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span>n <span style="color: #339933;">=</span> array.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>array<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        a.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #339933;">--</span>length<span style="color: #339933;">;</span>
        <span style="color: #339933;">--</span>i<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>an optimized fast performances version could avoid the inline splice and store those index to discard (splice could cost a lot) in order to push only certain indexes (not duplicated)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pankaj</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-805</link>
		<dc:creator>Pankaj</dc:creator>
		<pubDate>Tue, 08 Dec 2009 11:22:36 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-805</guid>
		<description>Another great post as usual. Had checked out prototype.js sometime back but never dojo. Now that you mention it, will surely try my hands on it.</description>
		<content:encoded><![CDATA[<p>Another great post as usual. Had checked out prototype.js sometime back but never dojo. Now that you mention it, will surely try my hands on it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tweets that mention Deduplicate any array in Javascript &#124; Unscriptable.com -- Topsy.com</title>
		<link>http://unscriptable.com/index.php/2009/12/08/deduplicate-any-array-in-javascript/comment-page-1/#comment-802</link>
		<dc:creator>Tweets that mention Deduplicate any array in Javascript &#124; Unscriptable.com -- Topsy.com</dc:creator>
		<pubDate>Tue, 08 Dec 2009 07:35:50 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=467#comment-802</guid>
		<description>[...] This post was mentioned on Twitter by John Hann, jonathan &#039;j5&#039; cook. jonathan &#039;j5&#039; cook said: RT @unscriptable: Deduplicate any array in Javascript: http://bit.ly/7taOgm (Doesn’t everybody have to do this once in a while?) [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was mentioned on Twitter by John Hann, jonathan &#39;j5&#39; cook. jonathan &#39;j5&#39; cook said: RT @unscriptable: Deduplicate any array in Javascript: <a href="http://bit.ly/7taOgm" rel="nofollow">http://bit.ly/7taOgm</a> (Doesn’t everybody have to do this once in a while?) [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
