自定义函数比较返回错误值,但仅当较低值在3和9之间时。

huangapple go评论59阅读模式
英文:

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 &lt; numGames; i++){
    if(currentRange[i] &gt; 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 &gt; otherRange[i]*1)

huangapple
  • 本文由 发表于 2023年2月27日 01:11:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75573680.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定