From 674f45e8b83a0553e0ecb3d4da9afe70255e75cd Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:45:37 -0700 Subject: [PATCH] Optimize game.countPlayer. (cherry picked from commit df9c74b86040e6e576b643e8f094cec99372b397) --- game/game.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/game/game.js b/game/game.js index 20d3dca8c..ece9f4052 100644 --- a/game/game.js +++ b/game/game.js @@ -38739,22 +38739,15 @@ } return false; }, - countPlayer:function(func,includeOut){ - var num=0; - if(typeof func!='function'){ - func=lib.filter.all; - } - for(var i=0;i{ + if(typeof func!='function') func=lib.filter.all; + return game.players.reduce((previousValue,currentValue)=>{ + if(!includeOut&¤tValue.isOut()) return previousValue; + const result=func(currentValue); + if(typeof result=='number') previousValue+=result; + else if(result) previousValue++; + return previousValue; + },0); }, countPlayer2:(func,includeOut)=>{ if(typeof func!='function') func=lib.filter.all;