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.
Sure but it also specifies in the description, "a number between 0-9"
Nobody is saying its best practices for all scenarios but lets be honest, if its higher than what you're expecting, returing a default of zero is fine imo.
I guess it's the overflow considerations?
what is meant with the "worst case" ?
It should panic, according to the description that's an invalid input.
If you enter 11 the code will panic. I don't think this is a "best practice."
If you enter 11 the code return "Zero". I don't think this is a "best practice."
The return type is not an
Option
, so what else can you do? The only other thing is to use a checked operation explicitly so that it remains in the release configuration, but it isn't the default choice.This code compiles for the pre-set test but does not consider the worst case. It is not a good practice not to consider the worst case. For example: If you enter an i32::Max or an i32::Min as a parameter, this code will panic. Reporting this code as "Best Practice" is not a good sign of knowing how to look deeply into the problem that has been posed.
If the goal is to pass the test, that's fine. But this code cannot be considered best practice because it does not consider the worst case.