js 删除数组重复元素...
时间:2010-08-17 来源:potato9
(function() { var distin = { numArray: function() { var num = [], i = 0; for (i; i < 10; i++) { num.push(this.rand(10)); } return num; }, disp: function(array, title) { if (!array) { array = distin.numArray(); } if (title) { document.write("<br />" + title); } for (var i in array) { document.write(" [ " + array[i] + " ] "); } }, rand: function(param) { return Math.ceil(Math.random() * param); }, find: function(array) { for (var i = 0; i < array.length; i++) { if (array[i] === array[i + 1]) { array.splice(i, 1); i--; } } return array; }, sortNum: function(a, b) { return a - b; }, dispSort: function() { var array = this.numArray().sort(this.sortNum); this.disp(array); }, run: function() { var array = this.numArray(); this.disp(array, "BEGIN: "); array.sort(this.sortNum); this.disp(array, "SORT: ") this.find(array); this.disp(array, "RESULT: ") } } window.distin = distin; })(); distin.run();