Optimize game.countPlayer.
(cherry picked from commit df9c74b86040e6e576b643e8f094cec99372b397)
This commit is contained in:
parent
ed19d18f75
commit
674f45e8b8
25
game/game.js
25
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<game.players.length;i++){
|
||||
if(!includeOut&&game.players[i].isOut()) continue;
|
||||
var result=func(game.players[i]);
|
||||
if(typeof result=='number'){
|
||||
num+=result;
|
||||
}
|
||||
else if(result){
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
countPlayer:(func,includeOut)=>{
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue