Ad
  • Custom User Avatar

    Your code is wrong because upon cnt exceeds n, each element after the first occurrence of such cases will be continuously removed from copy until the last element. Whilst the task asks us to remove elements until there are <= n remaining in the original array.

  • Custom User Avatar

    Not only you are modifying the original array which is bad practice, but also your conditional check is wrong. (Re-read the description)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Don't modify the input.

  • Custom User Avatar
  • Custom User Avatar

    Why was Voile's answer downvoted?

    Voile is correct - the example returns 6 because from the input (-2, 1, -3, 4, -1, 2, 1, -5, 4) you have to find the sequence which yields the highest sum.

    That (as Voile correctly states) is "4, -1, 2, 1" because 4 - 1 = 3, then 3 + 2 = 5, then 5 + 1 = 6. There are negative numbers before (-3) and after (-5) this sub-sequence so the sub-sequence in the result is the yields the highest sum.

  • Custom User Avatar

    [4, -1, 2, 1]

  • Custom User Avatar

    I literally admitted to being new, thanks for being passive aggressive

    No, you admitted that you're writing code, having no idea what it's doing or why it's doing so. This is fine, and it's okay to ask people for help, but this is not an excuse for acting like an ass.

    without context, I dont understand how you are getting your returns

    These are not my returns, these are your returns. I thought you'd understand this unless you're new to understanding stuff as well.

  • Custom User Avatar

    I don't choose which numbers make it up

    I think you don't really understand what you're doing O_o

    Anyway:

    [1, 0, 2]  <- array of even numbers, e == true,  returns 1
    [0, 1, 2]  <-                        e == true,  returns 1
    [0, 2, 1]  <-                        e == false, returns 0
    
    [2, 1, 3]  <- array of odd numbers, e == false, returns 2
    [1, 2, 3]  <-                       e == false, returns 2
    [1, 3, 2]  <-                       e == true,  returns 1
    
  • Custom User Avatar

    Looks like the logic in your first loop is flawed, and you check which numbers (even/odd) make up the array incorrectly.

  • Custom User Avatar

    Okay, pass these test cases then:

    Test.assertEquals(isPangram("abcdefghijklmnopqrstuvwxyz1"), true);
    Test.assertEquals(isPangram("abcdefghijklmnopqrstuvwxyyy"), false);
    Test.assertEquals(isPangram("abcdefghijklmnopqrstuvwxyzz"), true);
    
  • Custom User Avatar

    But your code only returns true if the string is empty after you cleared the letters (e.g "abcdefghijklmnopqrstuvwxyz1").

    Also note that you're returning null in the end, which is a wrong return value.

    Also note that your code fails for pangrams with the same letter occuring twice (e.g "abcdefghijklmnopqrstuvwxyzz").

    In short, if you can't come up with the specific test cases that breaks your code, it will be very hard to debug ;-)

    I also avoid using regex by the way.

    Why would you do that? ;-)

  • Custom User Avatar

    What if there are non-letters in the input? From the description:

    Ignore numbers and punctuation.

  • Custom User Avatar

    Already told you you're confusing the tests values, write console.log(a, b); as the first line in your function, the console.log data comes before the test result message, so you're actually seeing the input values of the next test, not the one your function is failing with the code you wrote.
    I've changed the tests to be more specific, try now, after clicking reset.

  • Custom User Avatar

    Use spoiler tag when posting code like that and use proper markdown
    Your code returns [1, 2] not [] with the input you wrote. Maybe you're confusing the input log with the previous/next test. Use console.log inside your function to see what a and b are. Mutating an array you're going through with a loop is a very bad idea, you skip values like that. Your code is wrong, fix it.