最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript數(shù)字?jǐn)?shù)組去重復(fù)項(xiàng)的實(shí)現(xiàn)代碼

 更新時(shí)間:2010年12月30日 19:33:57   作者:  
console.log 不支持ie,下面的代碼需要在火狐中測試,不然會有問題。
test.htm
復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>array-remove-repeate</title>
<style>
.tt{ background-color:#006699; height:3px; overflow:hidden;}
</style>

</head>

<body>
<div class="tt"></div>
<div class="result" id="result"></div>
<script>

if(!console)
{
var console={};
console.log=function(str){alert(str);}
}

Array.prototype.unique1 = function () {
var r = new Array();
label:for(var i = 0, n = this.length; i < n; i++) {
for(var x = 0, y = r.length; x < y; x++) {
if(r[x] == this[i]) {
continue label;
}
}
r[r.length] = this[i];
}
return r;
}

Array.prototype.unique2 = function () {
return this.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
}

Array.prototype.unique3 = function() {
var temp = {}, len = this.length;
for(var i=0; i < len; i++) {
var tmp = this[i];
if(!temp.hasOwnProperty(tmp)) {
temp[this[i]] = "my god";
}
}

len = 0;
var tempArr=[];
for(var i in temp) {
tempArr[len++] = i;
}
return tempArr;
}
Array.prototype.unique4 = function () {
var temp = new Array();
this.sort();
for(i = 0; i < this.length; i++) {
if( this[i] == this[i+1]) {
continue;
}
temp[temp.length]=this[i];
}
return temp;

}


var test=(function()
{
var arr2=[];
for(var i=0;i<2000;i++)
{
var t=i;
t=parseInt(Math.random()*2000)+1;
arr2[i]=(t.toString());


}
//arr2=["zhoujian","zhou","zhou"];
return function(){
return arr2;
//return [1,2,3,3];
};


})();
window.onload=function(){


//
Watch.start("Cost times1:");
var arr= test();
console.log(arr.length );

arr=arr.unique1();
console.log(arr.length);

Watch.stop();
//
Watch.start("Cost times2:");
arr= test();
console.log(arr.length);


arr=arr.unique2();

console.log(arr.length);

Watch.stop();
//
Watch.start("Cost times3:");
arr= test();
console.log(arr.length );

arr=arr.unique3();//數(shù)組很大時(shí),最快

console.log(arr.length );

Watch.stop();

//

Watch.start("Cost times4:");
arr= test();
console.log(arr.length);
arr=arr.unique4();
console.log(arr.length);
Watch.stop();
Watch.report();

}
</script>
</body>
</html>

Watch.js
復(fù)制代碼 代碼如下:

var Watch = {
result: [],
guid: -1,
totalTime: 0,
start: function(title){
this.result[++this.guid] = [title || this.guid, new Date().getTime()];
},
stop: function(){
var r = this.result[this.guid];
var t = new Date().getTime() - r[1];
this.totalTime += t;
r[1] = t;
if(t>=10000){
alert("This code takes too long to run,you should optimizate them.");
}
},
report: function(parent){
var div = document.createElement("div");
div.style.fontSize = "12px";
var str = [];
str.push("<p><b>The total times:</b><span style='color:#f00'>" + this.totalTime + "</span> ms.</p>");
for (var i = 0, l = this.result.length; i < l; i++) {
if (this.result[i].length > 1) {
str.push("<p>" + "<span style='width:200px;display:inline-block;background-color:#f7f7f7;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;'>"+"<span style='background-color:#0c0; -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;width=" + (this.totalTime === 0 ? this.totalTime : parseInt(200 * this.result[i][1] / this.totalTime)) + "px; display:inline-block;'>"+this.result[i][1]+"</span>"+"</span> <span style='width:150px; display:inline-block;'>" + this.result[i][0] + "</span>" + "</p>");
}else{
str.push(this.result[i][0]);
}
}
div.innerHTML = str.join("");
parent = parent || document.body;
parent.appendChild(div);
div = null;

this.totalTime = 0;
this.guid = -1;
this.result=[];
},
fns: function(){
var a = arguments;
for (var i = 0, l = a.length; i < l; i++) {
this.start(a[i][0]);
a[i][1]();
this.stop();
}
},
execByTimes: function(fn, times, title){
this.start(title);
while (times--) {
fn();
}
this.stop();
},
print: function(str){
this.result[++this.guid]=[str];
}
}

相關(guān)文章

  • JS操作時(shí)間 - UNIX時(shí)間戳的簡單介紹(必看篇)

    JS操作時(shí)間 - UNIX時(shí)間戳的簡單介紹(必看篇)

    下面小編就為大家?guī)硪黄狫S操作時(shí)間 - UNIX時(shí)間戳的簡單介紹(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • JS用斜率判斷鼠標(biāo)進(jìn)入DIV四個(gè)方向的方法

    JS用斜率判斷鼠標(biāo)進(jìn)入DIV四個(gè)方向的方法

    在網(wǎng)上去搜判斷鼠標(biāo)移入div移入移出的方法大同小異,下面小編給大家分享一篇文章關(guān)于js判斷鼠標(biāo)進(jìn)入div方向的代碼,感興趣的朋友一起看看吧
    2016-11-11
  • JavaScript中的console.trace()函數(shù)介紹

    JavaScript中的console.trace()函數(shù)介紹

    這篇文章主要介紹了JavaScript中的console.trace()函數(shù)詳細(xì)介紹,console.trace()函數(shù)用來打印函數(shù)調(diào)用的棧信息,需要的朋友可以參考下
    2014-12-12
  • video.js添加自定義組件的方法

    video.js添加自定義組件的方法

    這篇文章主要介紹了videojs添加自定義組件的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • js改變html的原有內(nèi)容實(shí)現(xiàn)方法

    js改變html的原有內(nèi)容實(shí)現(xiàn)方法

    下面小編就為大家?guī)硪黄猨s改變html的原有內(nèi)容實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-10-10
  • js中最容易被忽視的事件問題大總結(jié)

    js中最容易被忽視的事件問題大總結(jié)

    下面小編就為大家?guī)硪黄猨s中最容易被忽視的事件問題大總結(jié)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨小編過來看看吧,祝大家游戲愉快哦
    2016-05-05
  • 關(guān)于include標(biāo)簽導(dǎo)致js路徑找不到的問題分析及解決

    關(guān)于include標(biāo)簽導(dǎo)致js路徑找不到的問題分析及解決

    本文為大家詳細(xì)介紹下關(guān)于使用jsp:include標(biāo)簽及<%@ include標(biāo)簽時(shí)要注意的事項(xiàng)以及實(shí)測發(fā)現(xiàn)問題并解決問題的全過程,感興趣的各位可以參考下哈,希望對大家有所幫助
    2013-07-07
  • 微信小程序自定義組件實(shí)現(xiàn)單選功能

    微信小程序自定義組件實(shí)現(xiàn)單選功能

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義組件實(shí)現(xiàn)單選功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • jQuery實(shí)現(xiàn)手風(fēng)琴特效

    jQuery實(shí)現(xiàn)手風(fēng)琴特效

    這篇文章主要為大家詳細(xì)介紹了前端js實(shí)現(xiàn)手風(fēng)琴效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • 關(guān)于使用js算總價(jià)的問題

    關(guān)于使用js算總價(jià)的問題

    下面小編就為大家?guī)硪黄P(guān)于使用js算總價(jià)的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06

最新評論

青神县| 龙山县| 西华县| 繁峙县| 义马市| 虎林市| 鄢陵县| 龙南县| 邓州市| 长春市| 涿鹿县| 武邑县| 绥化市| 肇源县| 关岭| 安徽省| 桐城市| 府谷县| 正蓝旗| 乐亭县| 九龙坡区| 上蔡县| 鲜城| 东丽区| 宁阳县| 陈巴尔虎旗| 定襄县| 郴州市| 孟村| 茌平县| 溆浦县| 综艺| 西林县| 乳源| 和平县| 体育| 林甸县| 桃源县| 南郑县| 义马市| 临沭县|