From 6659d861d4e7458eb4d9e4492e7a3e71ba9db1c2 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Mon, 9 Oct 2023 09:27:02 +0800 Subject: [PATCH] =?UTF-8?q?addArray=E5=8E=BB=E9=87=8D=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index 6bfef6ec6..ba6f9e00d 100644 --- a/game/game.js +++ b/game/game.js @@ -8493,14 +8493,16 @@ if(arguments.length>0){ //参数去重,防止出现addArray(arr ,arr ,arr)的问题 let args=[...new Set(arguments)]; - //展开参数数组,并再次去除所有重复元素(没测试过concat的性能) + //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=>!this.includes(v)); + .filter(v=>!unique.has(v)); //添加元素 this.push(...all); }