Ad
  • Custom User Avatar

    Done! Thanks for the translation

  • Custom User Avatar

    I got your point, but since the Edge case section has instructions on how to deal with null, I think it's might be fine to handle the invalid input in a more forgiving way (return 0).

    Thanks for the great discussion and helping me to improve the Kata!

  • Custom User Avatar

    Thanks for your comments and help to improve this Kata!

  • Custom User Avatar

    Updated example test, also added random tests.

  • Custom User Avatar

    Random tests added, thanks.

  • Custom User Avatar

    Thanks lot for your help, I've added random tests now!

  • Custom User Avatar

    Thanks for your comment, I'm viewing it from a different angle: we should be teaching students not to trust the input from users, or rely on the callee to pass in valid parameters.
    Good students will raise questions like What happens when I call it with null/nothing/wrong type and that's why I added the Edge case section to encourage them to handle invalid parameters.

  • Custom User Avatar

    I've updated the tests now, and you were right about mathEngine([-5]) == -4, thanks for your input!

  • Custom User Avatar

    I recently joined codewars, most of the Katas I worked on are testing those edge cases. Like you said lots people wrote their TDD/BDD tests with testing aginst the null.
    The way I interpret it is because the authors want to check the invalid input cases, and make sure the Kata can handle them. That's why I followed this way, but like you said, it's not be the correct user input of an array but I think for testing it's fine to include it and mention it in description.

  • Custom User Avatar

    I appreciate all your comments and suggestions, also I've been updating/improving the Kata based on your comment.

  • Custom User Avatar

    Then in this case, [] should return 1 as result?

  • Custom User Avatar

    In most OO languages, null is a reference/pointer to nothing.
    In javascript, if you are familiar with prototype inheritance, you know that in the prototype chain, array is an object and also the end of that chain (from object) is null.

    If you want to learn more about it, please see https://developer.mozilla.org/en/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

  • Custom User Avatar

    I will update the description again, if you think it's hard to understand.

    These are more for my students who just learn JS for a week.. I guess you used reduce with base 1 so you got // product([]) == 1. But if you code it correctly it should get the expected result.

    Happy coding/reviewing Kata!

  • Custom User Avatar

    I've already updated the description, please refresh and you will see non-negative now.

  • Custom User Avatar

    Exactly. Imagine [] is an array that has no positive nor negative element. Then we are adding 0 with -0, which will get the result in "Edge cases".

  • Loading more items...