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.
I like this solution, very readable.
I don't see any 'good' or 'bad' practices here.
Please, correct me if I'm wrong.
For me, this question is rather a matter of taste. Because at the end of the day you end with the same instructions, the only difference is the structure of the code.
Hence there are no other differences the choice must be based on readability. And as for me, for-loop is more readable due to its conciseness.
In general, it's not a good practice to reassign the method argument.
If you are curious why - then please look at these method signatures.
It's a pretty helpful example because Node arguments have a meaningful name (and in general they must be meaningful).
And then if we treat an argument head as a usual variable its name becomes pointless.
And moreover in the case, if a method is much larger than a few lines or has an intricate logic then it's easy to introduce a bug because you forget that 'head' no longer points to the head.
i agree a while loop might be more readable here, thanks
Having a for loop that stops on a condition not related to the defined variable "i" is not a good practice. Usually for loops are used to traverse exhaustively, for example in an array or collection. If you don't know for sure when a loop should stop and you depend on an external condtion as in this case, it is better to use a while loop.
Sometimes I would also like more fine-grained upvotes.
Clever
doesn't feel right for readable / maintainable but with underwhelming performance;Best practice
is only for maintainable and performant.Downvotes are a minefield I can see CodeWars not getting into.
Yeah I know I can use them for those. But I would rather if I could mark one solution as it has good performance and is readable and some other with clever as it is nice one-liner than to have to mark both with clever/best practices and have no option other than comments to differentiate between those two.
I think performance is important feature enough to have its own label.
It is not new, there are several issues on github like https://github.com/Codewars/codewars.com/issues/1891
You use 'best practices' and 'clever' for those too.
Hello there, nice site, even though the slowness of it is sometimes frustrating.
I have a suggestion about labeling solutions of a particular kata. To this day user can label each solution with 'Best practice' and/or 'Clever'. I think it would be nice if there would be more:
Something like 'Most readable' or 'Nice to read' (that doesn't always has to mean best practice).
Something like 'Good/bad performance'.
I found it often that there are solutions on top of ratings that are both not so easy to read and have a bad performance. And people have to write these in the comments.
As this should serve as a learning platform it would be nice if also solutions that are easier to read and therefore easier to maintain, perform better and are less error prone had some more praise here.
Isn't it possible that the execution would end with StackOverflowError for really large Linked list? Because of the recursion? Just to make myself sure...