首页 > 编程语言 > 详细

Remove Duplicates from Sorted Array by Javascript

时间:2017-09-05 16:20:57      阅读:257      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/calvinzqz/p/7479140.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!