Compare the Triplets

  • + 9 comments

    I'm using Javascript and for me it's saying my output is correct, but it's not letting me move on because of a runtime error on line 47 with result.join being undefined.

    • + 0 comments

      Same problem here!

    • + 0 comments

      Same here :(

    • + 3 comments

      same here. I kept losing my cool, thinking I did something wrong. I tried multiple solutions, arrived at the correct output 3 -way times, but getting a runtime error with result.join as you say. Same for python. LAME!

      • + 1 comment

        If you are using JS, just do it. Change the line 55 for "ws.write(result += "\n");"

        • + 1 comment

          I'm having same problem. The code works for my test cases, but does not let me submit due to error of "join" not being recognized.

          Victorviannaribe1 your solution doesnt work. Tenta de novo

          • + 0 comments

            Is your function returning a string? If so, this is the issue. The join method expects an array, so you want to be returning something in the format [aScore, bScore].

            Then, result.join will convert the array into the expected output format.

            This at least worked for me, hope my explanation is of some use to you

      • + 3 comments

        I got a same error so I tried to return array. Then it fixed.

        var result = [];
        var aScore = 0,
            bScore = 0;
        
        for (var i = 0; i < a.length; i++) {
            if (a[i] > b[i]) aScore++;
            if (a[i] < b[i]) bScore++;
        }
        result[0] = aScore;
        result[1] = bScore;
        return result;
        
        • + 0 comments

          var a = [a0, a1, a2]; var b = [b0, b1, b2]; var ascore = 0; var bscore = 0;

          function compareTriplets(a0, a1, a2, b0, b1, b2) { var resultsArray = [];

          for (var i = 0; i < a.length; i ++) {

          if (a[i] > b[i]) {
              ascore++
          }
          
          if (a[i] < b[i]) {
              bscore++
          }   
          

          } resultsArray[0] = ascore; resultsArray[1] = bscore; return (ascore + "" + bscore) }

        • + 0 comments

          Wow! It really helped dude. Thank you.

        • + 0 comments

          i have same problem, returned array done thank you

      • + 0 comments

        You have built the best script from python which is every difficult programming. But still it's failing in the execution process, which is the saddest thing. I have been trying to write a papersowl reviews article on this code based upon your articles. And trying to make a good script to make own website. I hope it turns well.

    • + 0 comments

      Yea if you chose the JavaScript (nodejs) template for the response, the solve method expects you to return an array.

      [scoreAlice scoreBob]

      But tbh you should be able to figure that out by reading the error ;) Good luck.

    • + 0 comments
      • // Complete the compareTriplets function below.
      • function compareTriplets(a, b) {
      • let res = [0,0];
      • for (let i = 0; i < a.length; i++) {
      • if (a[i]!== b[i]) {
      • a[i] > b[i] ? res[0]++ : res[1]++;
      • }
      • }
      • return res;
      • }
    • + 0 comments

      Same problem here

    • + 0 comments

      edit the original code to

      ws.write(result + '\n');

      and run again

    • + 0 comments

      add .("")