标签:this cti array and his function shuffle 元素 prototype
//利用洗牌算法
Array.prototype.shuffle=function(){
var i,t,m=this.length;
while(m){
i=Math.floor(Math.random()*m--);
t=this[m];
this[m]=this[i];
this[i]=t;
}
return this;
}
var arr=[1,2,3,4,5];
console.log(arr.shuffle());
console.log(arr.slice(0,2));
标签:this cti array and his function shuffle 元素 prototype
原文地址:http://www.cnblogs.com/izengbin/p/6797503.html