From fc216fc8526b896a37066a18f514aa24b5d7f348 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Mon, 9 Oct 2023 08:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Array.prototype.addArray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index d9063bf2f..6bfef6ec6 100644 --- a/game/game.js +++ b/game/game.js @@ -8486,9 +8486,23 @@ configurable:true, enumerable:false, writable:true, + //与原来参数的对比: + //数据多,比原来的函数快 + //数据少,比原来的函数稍慢 value:function(){ - for(const arr of arguments){ - for(const item of arr) this.add(item); + if(arguments.length>0){ + //参数去重,防止出现addArray(arr ,arr ,arr)的问题 + let args=[...new Set(arguments)]; + //展开参数数组,并再次去除所有重复元素(没测试过concat的性能) + let all=Array.from( + new Set( + args.reduce((previous,current)=>previous.concat(current)) + ) + ) + //与this去重 + .filter(v=>!this.includes(v)); + //添加元素 + this.push(...all); } return this; }