【www.gdgbn.com--网页配色】

删除数组中数据

array.prototype.del = function(n)
{
if (n<0) return this;
return this.slice(0,n).concat(this.slice(n+1,this.length));
}
// 数组洗牌
array.prototype.random = function()
{
var nr=[], me=this, t;
while(me.length>0)
{
nr[nr.length] = me[t = math.floor(math.random() * me.length)];
me = me.del(t);
}
return nr;
}
// 数字数组排序
array.prototype.sortnum = function(f)
{
if (!f) f=0;
if (f==1) return this.sort(function(a,b){return b-a;});
return this.sort(function(a,b){return a-b;});
}
// 获得数字数组的最大项
array.prototype.getmax = function()
{
return this.sortnum(1)[0];
}
// 获得数字数组的最小项
array.prototype.getmin = function()
{
return this.sortnum(0)[0];
}
// 数组第一次出现指定元素值的位置
array.prototype.indexof = function(o)
{
for (var i=0; i return -1;
}
// 移除数组中重复的项
array.prototype.removerepeat=function()
{
this.sort();
var rs = [];
var cr = false;
for (var i=0; i {
if (!cr) cr = this[i];
else if (cr==this[i]) rs[rs.length] = i;
else cr = this[i];
}
var re = this;
for (var i=rs.length-1; i>=0; i--) re = re.del(rs[i]);
return re;
}

本文来源:http://www.gdgbn.com/wangyezhizuo/28282/