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.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
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.
The exercise instructions clearly state this, which makes it a requirement.
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.
Not exists validation for negative numbers
This comment is hidden because it contains spoiler information about the solution
Wrong decision
Please, read the description again, it says the function receives non negative numbers. Also, mark your comment as having spoiler content next time.
This comment is hidden because it contains spoiler information about the solution
Do you think that it isn't respecting the rule of non negative numbers.
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.
You also need to change the return type to long.
I do agree that one liners are "clever" and should be upvoted, but are they really "Best Practices"? Surely best practices are one operation per line with clearly named variables holding the value for each operation?