Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Done! Thanks for the translation
I got your point, but since the
Edge case
section has instructions on how to deal withnull
, I think it's might be fine to handle the invalid input in a more forgiving way (return0
).Thanks for the great discussion and helping me to improve the Kata!
Thanks for your comments and help to improve this Kata!
Updated example test, also added random tests.
Random tests added, thanks.
Thanks lot for your help, I've added random tests now!
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 theEdge case
section to encourage them to handle invalid parameters.I've updated the tests now, and you were right about
mathEngine([-5]) == -4
, thanks for your input!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.
I appreciate all your comments and suggestions, also I've been updating/improving the Kata based on your comment.
Then in this case,
[]
should return 1 as result?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) isnull
.If you want to learn more about it, please see https://developer.mozilla.org/en/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
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!
I've already updated the description, please refresh and you will see
non-negative
now.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...