Ad
  • Default User Avatar

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

  • Default User Avatar

    The instructions state you won't get negative numbers on input, therefore IMO it's like a contract and you really don't need to count with negative numbers in this case. This is why the kata tests also pass because they won't send you any single negative number. Also check the similar answer from @Chrono79 below.

  • Custom User Avatar

    The exercise instructions clearly state this, which makes it a requirement.

  • Default User Avatar

    This is correct since the acceptance criteria don't expect negative numbers as input parameter. We are not trying to do classic sad path validation.

  • Custom User Avatar

    Not exists validation for negative numbers

  • Default User Avatar

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

  • Default User Avatar
  • Custom User Avatar

    Please, read the description again, it says the function receives non negative numbers. Also, mark your comment as having spoiler content next time.

  • Custom User Avatar

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

  • Custom User Avatar

    Do you think that it isn't respecting the rule of non negative numbers.

  • Custom User Avatar

    What do you expect to do for such a simple function then? Writing a dozen lines for no reasons?

    One liner for trivial tasks like this is best practice because code should be concise. If it's extended to lots of lines there is something wrong with the coder. (Just imagine what they're going to write for more complex tasks, 1k lines? How are you going to read that?) Kneejack response to short code by yelling "it's short hence it can't be readable/maintainable!" without even looking at the code is TRWTF and even an original sin, so please don't do that. I can also not read a long solution and instantly say it's "bloated, tl;dr" too.

  • Custom User Avatar

    No prob! Glad to help!

  • Custom User Avatar

    You're right. Thank you for help

  • Custom User Avatar

    You are getting an index out of bounds error because you are comparing an index to an array length. The index of the last number will be 1 less than the array length. So in this array: {3,2,1} the array length is 3, but the index of the last number is 2. So when you check middle_idx < array.Length, it makes it so that it tries to run one more time. On this last run, it tries to grab a number from array[3] which doesnt exist (this throws the error). To fix it, simply change array.Length to array.Length - 1

  • Custom User Avatar

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

  • Loading more items...