Posts Tagged ‘distinct’

十二月 27th, 2009

删除数组的重复项

9 Comments, 前端开发, by army8735.

怿飞在同名文章《删除数组中重复项(uniq)》中分享了他的方法,时间复杂度和空间复杂度均为O(n),但还无法解决弱类型的问题。凑巧我也思考过类似的方法,在此基础上修改一下,可以KO弱类型问题。
<script src=”mootools-1.2.4-core-nc.js”></script>
<script>
Array.implement({
distinct: function() {
if(this.length < 2) {
return this;
}
var hash = new Hash(), value;
outer:
for(var i = 0, len = this.length; i…