回滚addarray

This commit is contained in:
shijian 2023-10-11 09:55:57 +08:00
parent 191a704ddf
commit 493266d0c3
1 changed files with 2 additions and 18 deletions

View File

@ -8497,25 +8497,9 @@
configurable:true,
enumerable:false,
writable:true,
//与原来参数的对比:
//数据多,比原来的函数快
//数据少,比原来的函数稍慢
value:function(){
if(arguments.length>0){
//参数去重防止出现addArray(arr ,arr ,arr)的问题
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);
for(const arr of arguments){
for(const item of arr) this.add(item);
}
return this;
}