英文:
Custom function comparison returns incorrect value, but only when the lower value is between 3 and 9
问题
我正在为Google表格编写一个自定义函数,用于给我提供排球比赛的胜利/失败数值。为了做到这一点,我获取比赛的范围,如果当前范围中游戏1的值大于另一个范围中游戏1的值,就增加到胜利列。但是由于某种原因,当输球队的得分在3和9之间(包括3和9)时,它会说他们的得分更高(相对于25)。
function GETNUMWINS(currentRange, otherRange) {
var wins = 0;
var numGames = currentRange.length;
for(let i = 0; i < numGames; i++){
if(currentRange[i] > otherRange[i]){
wins++;
}
}
return wins;
}
例如,一场比赛:
球队A | 球队B |
---|---|
25 | 9 |
25 | 15 |
将导致该函数为每个球队返回1次胜利。
英文:
I am writing a custom function for google sheets to give me the win/loss values of volleyball matches. To do that I get the range of the games and just say if the current range value for game 1 is greater than the other range value for game 1, increase to the wins column. But for some reason, when the score for the losing team is between 3 and 9 (inclusive) it will say that they have the higher score (compared to 25).
function GETNUMWINS(currentRange, otherRange) {
var wins = 0;
var numGames = currentRange.length;
for(let i = 0; i < numGames; i++){
if(currentRange[i] > otherRange[i]){
wins++;
}
}
return wins;
}
For example, a match of
Team A | Team B |
---|---|
25 | 9 |
25 | 15 |
will result in that function returning 1 win for each team.
答案1
得分: 0
(currentRange[i]*1 > otherRange[i]*1)
英文:
Then it's probably considering the numbers as strings, subsequently considering "in alphabetical order" 3 greater than 25
Try:
(currentRange[i]*1 > otherRange[i]*1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论