Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Custom function comparison returns incorrect value, but only when the lower value is between 3 and 9

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading