I have a column “Win or Loss” that is a 0 or 1. It is the result of a formula in the Table. I would like to filter a result set to a certain number of rows in that table, which is working, and then sum the “Win or Loss” column. I figure this can be done with a reduce function. In this function which I call for each player, the goal is to calculate how many wins they have:
function getPlayerStats(player){
output.text(player);
let myGames = query.records.filter(record=>record.getCellValueAsString("Player")==player)
output.inspect(myGames);
let total_games=output.text(myGames.length);
let total_wins = myGames.reduce((total,record)=>total + record.getCellValue("Win or Loss"));
output.text(total_games);
output.text(total_wins);
}
The output for total_wins ends up being something like this:
>object Object]011
when it really should be 3 - it is concatenating the 1s but not summing them, and missing the first one for some reason. I am new to Javascript and so I figure I am missing something obvious. The warning message is
“Operator ‘+’ cannot be applied to types ‘Games_Players_RolesTable_Record’ and ‘number’.”
which explains why this is wierd, but I can’t figure out the right way to do it. Any pointers would be appreciated. Thank you!