Ad
  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    Nice one man!

  • Custom User Avatar

    Add console.log(x); inside your function, make it the first line. See the output panel, the last line you see there is the input that makes your code fail. Once you know which input makes your code fail, you can analyze where in your code you're making a mistake.

     assert.strictEqual(high('aa b'), 'aa');
    

    It's failing that one for instance.

  • Custom User Avatar

    To debug your code. See what the input is, and then you can try the same input in VSC.

  • Custom User Avatar

    Start by printing the input.

  • Custom User Avatar

    The fixed test your code isn't passing is this:

    Incorrect answer for input=[20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]: expected 4 to equal 5
    

    And the input is not an empty array. The javascript tests never pass an empty array to the function.

  • Custom User Avatar

    ... but its you who added a call with an empty array into your solution?
    Tests should not pass in empty arrays. Did you have such problem also before you added the call with empty array into your code?

  • Custom User Avatar
  • Custom User Avatar

    No, because the tests ask for two separate functions that do what I posted above. Normally, smaller and reutilizable functions are better than bigger and more complex ones.

    [4,6,2,1,9,63,-134,566]         -> max = 566, min = -134
    //                                 this isn't the formatted output, it's a comment 
    // This is a better example:
    max([4,6,2,1,9,63,-134,566]) -> 566
    min([4,6,2,1,9,63,-134,566]) -> -134
    
  • Custom User Avatar

    No, you're mistaken, -65 is the sum, not the count, and it's the same for all the other tests. A count would never be negative.

    Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.

    I don't know where are you seeing otherwise.

  • Custom User Avatar

    Count of positives / sum of negatives

    Where is the issue?

            10 positives
     v  v  v  v  v  v  v  v  v  v
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]
                                    -11 + (-12) + (-13) + (-14) + (-15) = -65
    
  • Custom User Avatar

    Your task is to make two functions ( max and min, or maximum and minimum, etc., depending on the language )

    Initial code:

    var min = function(list){
        
        return list[0];
    }
    
    var max = function(list){
        
        return list[0];
    }
    

    Two functions, each returns either the minimum or the maximum. Please mark your post as having spoiler content next time.

  • Custom User Avatar

    See the quotes around your answer, your function is returning a string instead of a number.