标签:logs sort prototype console color out not obj pre
Solution A:
1.Create a array store the result.
2.Create a object to store info of no- repeat element.
3.Take out the element of array, and judge whether in the object. If not push into result array.
Array.prototype.removeDuplicates = function(){ var res = []; var js = {}; for(var i = 0; i < this.length; i++){ console.log("**:" + i + " is :" + js[this[i]]); console.log(js); if(!js[this[i]]){ console.log(this[i]); res.push(this[i]); js[this[i]] = 1; } } return res; } var arr = [1,2,3,4,3,3,43,4,5,6,4,4,3,54,6,6]; arr.removeDuplicates();
Remove Duplicates from Sorted Array by Javascript
标签:logs sort prototype console color out not obj pre
原文地址:http://www.cnblogs.com/calvinzqz/p/7479140.html