<?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>评论：删除数组中重复项（uniq）</title>
	<atom:link href="http://www.planabc.net/2009/12/26/array_uniq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.planabc.net/2009/12/26/array_uniq/</link>
	<description>落草为根—专注前端技术&#38;&#38;关注用户体验</description>
	<lastBuildDate>Fri, 30 Jul 2010 03:14:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>来自：删除数组中重复项（uniq） - 隐遁峰</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-7849</link>
		<dc:creator>删除数组中重复项（uniq） - 隐遁峰</dc:creator>
		<pubDate>Fri, 04 Jun 2010 02:30:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-7849</guid>
		<description>[...] 如果大家想在此解题思路的基础上，更完美一点，推荐 Dexter.Yy 的方法，进行类型判断，给予唯一标示符，详见 评论 20 楼。 [...]</description>
		<content:encoded><![CDATA[<p>[...] 如果大家想在此解题思路的基础上，更完美一点，推荐 Dexter.Yy 的方法，进行类型判断，给予唯一标示符，详见 评论 20 楼。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：删除数组中重复项（uniq） ｜ 前端开发吧</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-7432</link>
		<dc:creator>删除数组中重复项（uniq） ｜ 前端开发吧</dc:creator>
		<pubDate>Wed, 28 Apr 2010 01:33:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-7432</guid>
		<description>[...] 如果大家想在此解题思路的基础上，更完美一点，推荐 Dexter.Yy 的方法，进行类型判断，给予唯一标示符，详见 评论 20 楼。 [...]</description>
		<content:encoded><![CDATA[<p>[...] 如果大家想在此解题思路的基础上，更完美一点，推荐 Dexter.Yy 的方法，进行类型判断，给予唯一标示符，详见 评论 20 楼。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：凌乱的JS例子整理 &#8211; 足跡偏右</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-7210</link>
		<dc:creator>凌乱的JS例子整理 &#8211; 足跡偏右</dc:creator>
		<pubDate>Thu, 15 Apr 2010 10:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-7210</guid>
		<description>[...] 3.快速去除数组重复项。来自怿飞的《删除数组中重复项（uniq）》 。 [...]</description>
		<content:encoded><![CDATA[<p>[...] 3.快速去除数组重复项。来自怿飞的《删除数组中重复项（uniq）》 。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：删除数组的重复项 &#173; army8735</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-6690</link>
		<dc:creator>删除数组的重复项 &#173; army8735</dc:creator>
		<pubDate>Sun, 07 Mar 2010 07:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-6690</guid>
		<description>[...] 怿飞在同名文章《删除数组中重复项（uniq）》中分享了他的方法，时间复杂度和空间复杂度均为O（n），但还无法解决弱类型的问题。凑巧我也思考过类似的方法，在此基础上修改一下，可以KO弱类型问题。 [...]</description>
		<content:encoded><![CDATA[<p>[...] 怿飞在同名文章《删除数组中重复项（uniq）》中分享了他的方法，时间复杂度和空间复杂度均为O（n），但还无法解决弱类型的问题。凑巧我也思考过类似的方法，在此基础上修改一下，可以KO弱类型问题。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Robin</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-6442</link>
		<dc:creator>Robin</dc:creator>
		<pubDate>Mon, 08 Feb 2010 14:52:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-6442</guid>
		<description>自己尝试写了一个，最坏的时间复杂度为O[0.5*n(n-1)]
支持任意混合类型
[code]
            if (Array.prototype.unique) {
                Array.prototype.unique = function(){
                    if (this.length  a.length) {//all done
                            break;
                        }
                    }
                    return a;
                }
            }
[/code]</description>
		<content:encoded><![CDATA[<p>自己尝试写了一个，最坏的时间复杂度为O[0.5*n(n-1)]<br />
支持任意混合类型<br />
[code]<br />
            if (Array.prototype.unique) {<br />
                Array.prototype.unique = function(){<br />
                    if (this.length  a.length) {//all done<br />
                            break;<br />
                        }<br />
                    }<br />
                    return a;<br />
                }<br />
            }<br />
[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：天堂左我往右</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5885</link>
		<dc:creator>天堂左我往右</dc:creator>
		<pubDate>Thu, 07 Jan 2010 13:47:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5885</guid>
		<description>加0真是个好方法...</description>
		<content:encoded><![CDATA[<p>加0真是个好方法&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：netwjx</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5865</link>
		<dc:creator>netwjx</dc:creator>
		<pubDate>Wed, 06 Jan 2010 08:19:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5865</guid>
		<description>重复push应该没有直接赋值快吧,可以使a初始为长度和arr长度相同,最后再slice,中间需要计算a的实际长度</description>
		<content:encoded><![CDATA[<p>重复push应该没有直接赋值快吧,可以使a初始为长度和arr长度相同,最后再slice,中间需要计算a的实际长度</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：kangre</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5834</link>
		<dc:creator>kangre</dc:creator>
		<pubDate>Sat, 02 Jan 2010 13:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5834</guid>
		<description>说不错，挺完善的！</description>
		<content:encoded><![CDATA[<p>说不错，挺完善的！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：cc</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5800</link>
		<dc:creator>cc</dc:creator>
		<pubDate>Wed, 30 Dec 2009 03:20:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5800</guid>
		<description>根据20楼的改一下
function unique(array) {
	var ret = [], record = {},it,tmp,obj = &quot;__object__&quot;, bak = [],i,len;
	var type ={
		&quot;number&quot;: function(n) { return &quot;__number__&quot; + n; },
		&quot;string&quot;: function(n) { return &quot;__string__&quot; + n; },
		&quot;boolean&quot;: function(n) { return &quot;__boolean__&quot; + n; },
		&quot;undefined&quot;: function(n) { return &quot;__undefined__&quot;; },
		&quot;object&quot;: function(n) {
			return n === null ? &quot;__null__&quot; : obj in n ? n[obj] : ( n[obj] = obj + bak.push(n) );
		}
	};
	for (i = 0, len = array.length; i &lt; len; i++) {
		it = array[i]; tmp = type[typeof it](it);
		if (!(tmp in record)) { ret.push(it); record[tmp] = true; }
	}
	for (i = 0, len = bak.length; i &lt; len; delete bak[i++][obj]) { }
	return ret;
};</description>
		<content:encoded><![CDATA[<p>根据20楼的改一下<br />
function unique(array) {<br />
	var ret = [], record = {},it,tmp,obj = &#8220;__object__&#8221;, bak = [],i,len;<br />
	var type ={<br />
		&#8220;number&#8221;: function(n) { return &#8220;__number__&#8221; + n; },<br />
		&#8220;string&#8221;: function(n) { return &#8220;__string__&#8221; + n; },<br />
		&#8220;boolean&#8221;: function(n) { return &#8220;__boolean__&#8221; + n; },<br />
		&#8220;undefined&#8221;: function(n) { return &#8220;__undefined__&#8221;; },<br />
		&#8220;object&#8221;: function(n) {<br />
			return n === null ? &#8220;__null__&#8221; : obj in n ? n[obj] : ( n[obj] = obj + bak.push(n) );<br />
		}<br />
	};<br />
	for (i = 0, len = array.length; i &lt; len; i++) {<br />
		it = array[i]; tmp = type[typeof it](it);<br />
		if (!(tmp in record)) { ret.push(it); record[tmp] = true; }<br />
	}<br />
	for (i = 0, len = bak.length; i &lt; len; delete bak[i++][obj]) { }<br />
	return ret;<br />
};</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：cc</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5799</link>
		<dc:creator>cc</dc:creator>
		<pubDate>Wed, 30 Dec 2009 00:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5799</guid>
		<description>20楼的不错哦
解决了object的问题</description>
		<content:encoded><![CDATA[<p>20楼的不错哦<br />
解决了object的问题</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：army8735</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5788</link>
		<dc:creator>army8735</dc:creator>
		<pubDate>Mon, 28 Dec 2009 12:59:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5788</guid>
		<description>前面+0这个方式很巧妙，我其实也想到了后面+类型这种作为key的方法。</description>
		<content:encoded><![CDATA[<p>前面+0这个方式很巧妙，我其实也想到了后面+类型这种作为key的方法。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Dexter.Yy</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5786</link>
		<dc:creator>Dexter.Yy</dc:creator>
		<pubDate>Mon, 28 Dec 2009 07:14:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5786</guid>
		<description>喔对了，忘了一件事情，我那个方法里面有用到jQuery.data，自己实现一个也很简短，就是给每个对象（包括DOM，函数，数组）生成一个唯一的流水号，绑在它的属性上，当然有些人可能不喜欢这样，不过绝大多数应用场合里是没影响的，换来的是简洁和效率</description>
		<content:encoded><![CDATA[<p>喔对了，忘了一件事情，我那个方法里面有用到jQuery.data，自己实现一个也很简短，就是给每个对象（包括DOM，函数，数组）生成一个唯一的流水号，绑在它的属性上，当然有些人可能不喜欢这样，不过绝大多数应用场合里是没影响的，换来的是简洁和效率</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：怿飞</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5784</link>
		<dc:creator>怿飞</dc:creator>
		<pubDate>Mon, 28 Dec 2009 06:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5784</guid>
		<description>@welefen  提供的写法是比较标准的写法，且对于FF3.5+等实现了Array.indexOf（）方法的浏览器来说，效果会更效率，期待未来所有浏览器都支持indexOf方法。

@Dexter.Yy 谢谢你的思路，很不错，昨天晚上也有想到过，非常感谢。</description>
		<content:encoded><![CDATA[<p>@welefen  提供的写法是比较标准的写法，且对于FF3.5+等实现了Array.indexOf（）方法的浏览器来说，效果会更效率，期待未来所有浏览器都支持indexOf方法。</p>
<p>@Dexter.Yy 谢谢你的思路，很不错，昨天晚上也有想到过，非常感谢。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：Dexter.Yy</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5779</link>
		<dc:creator>Dexter.Yy</dc:creator>
		<pubDate>Sun, 27 Dec 2009 16:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5779</guid>
		<description>啊，我是被army引来的～～

我在土豆网写一个实现，支持混合类型：

TUI.unique = function( array ) {
	var ret = [], record = {}, it, tmp;
	var type = {
		&quot;number&quot;: function(n){ return &quot;_TUI_num&quot; + n; },
		&quot;string&quot;: function(n){ return n; },
		&quot;boolean&quot;: function(n){ return &quot;_TUI_boolean&quot; + n; },
		&quot;object&quot;: function(n){ return n === null ? &quot;TUI_null&quot; : $.data(n); },
		&quot;undefined&quot;: function(n){ return &quot;_TUI_undefined&quot;; }
	};
	for ( var i = 0, length = array.length; i &lt; length; i++ ) {
		it = tmp = array[i];
		tmp = type[typeof it](it);
		if( !record[tmp] ) {
			ret.push(it);
			record[tmp] = true;
		}
	}
	return ret;
};

测试：

var b=[1,3,5];
TUI.unique([1,3,4,5,null,false,$(&quot;.pack&quot;)[0],b,&quot;ab&quot;,&quot;cc&quot;,[1,3],3,6,b,1,false,null,&quot;null&quot;,&quot;&quot;,&quot;false&quot;,&quot;&quot;,$(&quot;.pack&quot;)[0],&quot;cc&quot;]);</description>
		<content:encoded><![CDATA[<p>啊，我是被army引来的～～</p>
<p>我在土豆网写一个实现，支持混合类型：</p>
<p>TUI.unique = function( array ) {<br />
	var ret = [], record = {}, it, tmp;<br />
	var type = {<br />
		&#8220;number&#8221;: function(n){ return &#8220;_TUI_num&#8221; + n; },<br />
		&#8220;string&#8221;: function(n){ return n; },<br />
		&#8220;boolean&#8221;: function(n){ return &#8220;_TUI_boolean&#8221; + n; },<br />
		&#8220;object&#8221;: function(n){ return n === null ? &#8220;TUI_null&#8221; : $.data(n); },<br />
		&#8220;undefined&#8221;: function(n){ return &#8220;_TUI_undefined&#8221;; }<br />
	};<br />
	for ( var i = 0, length = array.length; i &lt; length; i++ ) {<br />
		it = tmp = array[i];<br />
		tmp = type[typeof it](it);<br />
		if( !record[tmp] ) {<br />
			ret.push(it);<br />
			record[tmp] = true;<br />
		}<br />
	}<br />
	return ret;<br />
};</p>
<p>测试：</p>
<p>var b=[1,3,5];<br />
TUI.unique([1,3,4,5,null,false,$(&quot;.pack&quot;)[0],b,&quot;ab&quot;,&quot;cc&quot;,[1,3],3,6,b,1,false,null,&quot;null&quot;,&quot;&quot;,&quot;false&quot;,&quot;&quot;,$(&quot;.pack&quot;)[0],&quot;cc&quot;]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：welefen</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5778</link>
		<dc:creator>welefen</dc:creator>
		<pubDate>Sun, 27 Dec 2009 15:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5778</guid>
		<description>通过对象的实现方式一种是给对象加个标记，如jquery实现方式，这种方式无法解决一些直接量，如111,&#039;abc&#039;,null等。
另一种是执行tostring方法，这种方式无法解决多个对象的tostring结果相同，如：new String(&#039;abc&#039;)和new String(&#039;abc&#039;)。
其实有一种更好的实现方式，并且实现效率上要高很多，即利用数组的lastIndexOf和splice方法。
http://www.welefen.com/javascript-array-unique/</description>
		<content:encoded><![CDATA[<p>通过对象的实现方式一种是给对象加个标记，如jquery实现方式，这种方式无法解决一些直接量，如111,&#8217;abc&#8217;,null等。<br />
另一种是执行tostring方法，这种方式无法解决多个对象的tostring结果相同，如：new String(&#8216;abc&#8217;)和new String(&#8216;abc&#8217;)。<br />
其实有一种更好的实现方式，并且实现效率上要高很多，即利用数组的lastIndexOf和splice方法。<br />
<a href="http://www.welefen.com/javascript-array-unique/" rel="nofollow">http://www.welefen.com/javascript-array-unique/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：巧妙去除数组中的重复项(续) - TCer&#39;s Blog</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5777</link>
		<dc:creator>巧妙去除数组中的重复项(续) - TCer&#39;s Blog</dc:creator>
		<pubDate>Sun, 27 Dec 2009 15:04:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5777</guid>
		<description>[...] 圆心的文章中, 对去除数组重复项的方法作了进一步的改进, 使得性能再次提升. 但如它文章中所提到的: 上述两种函数方法暂都无法处理好数字和数字字符串混合出现的情况，比如 [0,&quot;0&quot;,1,&quot;1&quot;,0]。, 这里, 我分享一下我的解决办法&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] 圆心的文章中, 对去除数组重复项的方法作了进一步的改进, 使得性能再次提升. 但如它文章中所提到的: 上述两种函数方法暂都无法处理好数字和数字字符串混合出现的情况，比如 [0,&quot;0&quot;,1,&quot;1&quot;,0]。, 这里, 我分享一下我的解决办法&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：怿飞</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5776</link>
		<dc:creator>怿飞</dc:creator>
		<pubDate>Sun, 27 Dec 2009 14:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5776</guid>
		<description>@army8735 你的方式不错，非常感谢，明天再修正一下。
@opomore 其实不仅仅是数字和数字字符有问题，比如类似这样的数组也同样有问题的：[null,&#039;null&#039;]。
@closurecache 最后提供的方法应该可以解决这样的问题，不过可能要验证下是不是所有的情况都可以。

还是，非常感谢大家的讨论和建议！</description>
		<content:encoded><![CDATA[<p>@army8735 你的方式不错，非常感谢，明天再修正一下。<br />
@opomore 其实不仅仅是数字和数字字符有问题，比如类似这样的数组也同样有问题的：[null,'null']。<br />
@closurecache 最后提供的方法应该可以解决这样的问题，不过可能要验证下是不是所有的情况都可以。</p>
<p>还是，非常感谢大家的讨论和建议！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：怿飞</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5775</link>
		<dc:creator>怿飞</dc:creator>
		<pubDate>Sun, 27 Dec 2009 14:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5775</guid>
		<description>@行骏 没什么区别的，主要不在于这个的改变，而在性能上的提升，呵呵</description>
		<content:encoded><![CDATA[<p>@行骏 没什么区别的，主要不在于这个的改变，而在性能上的提升，呵呵</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：天堂左我往右</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5774</link>
		<dc:creator>天堂左我往右</dc:creator>
		<pubDate>Sun, 27 Dec 2009 13:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5774</guid>
		<description>用两个object,一个放数字,一个放字符串,嘿嘿


数组不能是对象噢...</description>
		<content:encoded><![CDATA[<p>用两个object,一个放数字,一个放字符串,嘿嘿</p>
<p>数组不能是对象噢&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：army8735</title>
		<link>http://www.planabc.net/2009/12/26/array_uniq/comment-page-1/#comment-5771</link>
		<dc:creator>army8735</dc:creator>
		<pubDate>Sun, 27 Dec 2009 10:36:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.planabc.net/?p=338#comment-5771</guid>
		<description>http://army8735.org/2009/12/27/523.html
我也分享出来了。</description>
		<content:encoded><![CDATA[<p><a href="http://army8735.org/2009/12/27/523.html" rel="nofollow">http://army8735.org/2009/12/27/523.html</a><br />
我也分享出来了。</p>
]]></content:encoded>
	</item>
</channel>
</rss>
