回滚addarray
This commit is contained in:
parent
191a704ddf
commit
493266d0c3
20
game/game.js
20
game/game.js
|
@ -8497,25 +8497,9 @@
|
||||||
configurable:true,
|
configurable:true,
|
||||||
enumerable:false,
|
enumerable:false,
|
||||||
writable:true,
|
writable:true,
|
||||||
//与原来参数的对比:
|
|
||||||
//数据多,比原来的函数快
|
|
||||||
//数据少,比原来的函数稍慢
|
|
||||||
value:function(){
|
value:function(){
|
||||||
if(arguments.length>0){
|
for(const arr of arguments){
|
||||||
//参数去重,防止出现addArray(arr ,arr ,arr)的问题
|
for(const item of arr) this.add(item);
|
||||||
let args=[...new Set(arguments)];
|
|
||||||
//this -> Set
|
|
||||||
let unique=new Set(this);
|
|
||||||
//展开参数数组,并再次去除所有重复元素(concat(arr)和push(...arr)好像差不多)
|
|
||||||
let all=Array.from(
|
|
||||||
new Set(
|
|
||||||
args.reduce((previous,current)=>previous.concat(current))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
//与this去重
|
|
||||||
.filter(v=>!unique.has(v));
|
|
||||||
//添加元素
|
|
||||||
this.push(...all);
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue