Author:月影
From:http://bbs.51js.com/thread-66469-1-1.html
复制代码 代码如下:
<script>
function ArrayList()
{
var ins = Array.apply(this, arguments);
ins.constructor = arguments.callee;
ins.base = Array;
ins.each = function(closure)
{
if(typeof closure == 'undefined')
closure = function(x){return x};
if(typeof closure != 'function')
{
var c = closure;
closure = function(x){return x == c}
}
var ret = new ArrayList();
var args = Array.apply(this, arguments).slice(1);
for(var i = 0; i < this.length; i++)
{
var rval = closure.apply(this, [this[i]].concat(args).concat(i))
if(rval || rval === 0)
ret.push(rval);
}
return ret;
}
ins.trim = function()
{
return this.each.apply(this);
}
ins.all = function(closure)
{
return this.each.apply(this, arguments).length == this.length;
}
ins.any = function(closure)
{
return this.each.apply(this, arguments).length > 0;
}
ins.contains = function(el)
{
return this.any(function(x){return x == el});
}
ins.indexOf = function(el)
{
var ret = this.each.call(this, function(x, i){return el == x?i:false})[0];
return ret ? ret : -1;
}
ins.subarr = function(start, end)
{
end = end || Math.Infinity;
return this.each.call(this, function(x, i){return i >= start && i < end ? x : null});
}
ins.valueOf = ins.toString;
ins.toString = function()
{
return '['+this.valueOf()+']';
}
ins.map = function(list, closure)
{
if (typeof list == 'function' && typeof closure != 'function')
{
var li = closure;
closure = list;
list = li;
}
closure = closure || ArrayList;
return this.each.call(this, function(x, i){return closure.call(this, x, list[i])});
};
ins.slice = function()
{
return this.constructor(ins.base.prototype.slice.apply(this, arguments));
}
ins.splice = function()
{
return this.constructor(ins.base.prototype.splice.apply(this, arguments));
}
ins.concat = function()
{
return this.constructor(ins.base.prototype.concat.apply(this, arguments));
}
return ins;
}
var a = new ArrayList(1,2,3);
alert(a.length);
alert(a);
alert(a instanceof Array);
alert(a.constructor);
alert(a instanceof ArrayList); // 可惜这个值不对,但是没法实现,只好放弃了
alert(a.each(function(x){return x+x}));
alert(a.all(function(x){return x>0}));
alert(a.all(function(x){return x<1}));
alert(a.any(function(x){return x == 2}));
alert(a.contains(2));
alert(a.contains(-1));
var b = a.map([3,2], function(x, y){return x+y});
alert(b);
alert(a.map([2,3,4]));
alert(a.indexOf(2));
alert(a.indexOf(-1));
alert(a.subarr(1,3));
alert(a.toString());
var b = new ArrayList(a,a);
alert(b.toString());
alert(b.slice(1));
</script>
arr.all 是当数组(集合)中的所有元素都满足条件时,返回true,否则返回false
arr.any 是当数组(集合)中的所有元素中任意一个满足条件时,返回true,如果都不满足,返回false
arr.each 返回由符合条件的每一个元素构成的子数组
arr.map 是匹配两个数组(集合)并把它们的元素用指定闭包进行计算
From:http://bbs.51js.com/thread-66469-1-1.html
复制代码 代码如下:
<script>
function ArrayList()
{
var ins = Array.apply(this, arguments);
ins.constructor = arguments.callee;
ins.base = Array;
ins.each = function(closure)
{
if(typeof closure == 'undefined')
closure = function(x){return x};
if(typeof closure != 'function')
{
var c = closure;
closure = function(x){return x == c}
}
var ret = new ArrayList();
var args = Array.apply(this, arguments).slice(1);
for(var i = 0; i < this.length; i++)
{
var rval = closure.apply(this, [this[i]].concat(args).concat(i))
if(rval || rval === 0)
ret.push(rval);
}
return ret;
}
ins.trim = function()
{
return this.each.apply(this);
}
ins.all = function(closure)
{
return this.each.apply(this, arguments).length == this.length;
}
ins.any = function(closure)
{
return this.each.apply(this, arguments).length > 0;
}
ins.contains = function(el)
{
return this.any(function(x){return x == el});
}
ins.indexOf = function(el)
{
var ret = this.each.call(this, function(x, i){return el == x?i:false})[0];
return ret ? ret : -1;
}
ins.subarr = function(start, end)
{
end = end || Math.Infinity;
return this.each.call(this, function(x, i){return i >= start && i < end ? x : null});
}
ins.valueOf = ins.toString;
ins.toString = function()
{
return '['+this.valueOf()+']';
}
ins.map = function(list, closure)
{
if (typeof list == 'function' && typeof closure != 'function')
{
var li = closure;
closure = list;
list = li;
}
closure = closure || ArrayList;
return this.each.call(this, function(x, i){return closure.call(this, x, list[i])});
};
ins.slice = function()
{
return this.constructor(ins.base.prototype.slice.apply(this, arguments));
}
ins.splice = function()
{
return this.constructor(ins.base.prototype.splice.apply(this, arguments));
}
ins.concat = function()
{
return this.constructor(ins.base.prototype.concat.apply(this, arguments));
}
return ins;
}
var a = new ArrayList(1,2,3);
alert(a.length);
alert(a);
alert(a instanceof Array);
alert(a.constructor);
alert(a instanceof ArrayList); // 可惜这个值不对,但是没法实现,只好放弃了
alert(a.each(function(x){return x+x}));
alert(a.all(function(x){return x>0}));
alert(a.all(function(x){return x<1}));
alert(a.any(function(x){return x == 2}));
alert(a.contains(2));
alert(a.contains(-1));
var b = a.map([3,2], function(x, y){return x+y});
alert(b);
alert(a.map([2,3,4]));
alert(a.indexOf(2));
alert(a.indexOf(-1));
alert(a.subarr(1,3));
alert(a.toString());
var b = new ArrayList(a,a);
alert(b.toString());
alert(b.slice(1));
</script>
arr.all 是当数组(集合)中的所有元素都满足条件时,返回true,否则返回false
arr.any 是当数组(集合)中的所有元素中任意一个满足条件时,返回true,如果都不满足,返回false
arr.each 返回由符合条件的每一个元素构成的子数组
arr.map 是匹配两个数组(集合)并把它们的元素用指定闭包进行计算
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月30日
2024年11月30日
- 群星《人声1号[十大发烧情歌]》2CD[WAV分轨]
- 《郁可唯所有歌曲合集》[FLAC/MP3][6.2G]
- 郑秀文《SOUND OF MI》2024 7月新专辑[FLAC/MP3][1.1G]
- 费玉清《费玉清精粹》[FLAC][1G]
- 黑豹乐队-至爱极品顶级享受《豹行天下3CD》[WAV分轨]
- 音响系统测试碟《AbsoluteSamplerOnTheFly》[WAV+CUE]
- 一流的爵士乐《FirstClassJazz》ArtBlakey[正版原抓WAV+CUE]
- 杨千嬅《狼来了》[DSF][1.2G]
- 车载《旧情绵绵一路伴随》80后经典[FLAC/MP3][1G]
- 刀郎《身披彩衣的姑娘》[FLAC][1.4G]
- 张国荣《MissYouMix》美压版[正版原抓WAV+CUE]
- 长笛和吉他的浪漫音乐《OriginalRomanticMusicforFluteandGuitar》[WAV+CUE]
- 窦唯《八段锦》(上海音像)[WAV+CUE]
- DJ动力100%《堵在路上的解闷high曲》[FLAC/MP3][948M]
- 节奏炸裂《抖音最嗨 DJ 舞曲大合集》[FLAC/MP3][2G]