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.
Smart! I didn't think that taking the modulus would work like that.
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.
still no answer, some kind of magic... :)
right, there is also "getOrDefault" method - may be worth to consider.
I was worried the Garbage Collector might get bored if it had nothing to do.
Not sure about this solution. While the code looks simpler it is not a best practice. It creates a new object everytime you have a consecutive word. In this case it isn't a big deal, but in general it is better to avoid the creation of objects like this, as they are just temporal, and their lifetime is within a loop. In more complex scenarios this could lead to waste of memory and bad performance. It is not a good practice.
This is a really bad solution, at least regarding performance, and definitely not a "Best Practice". These are the issues:
To fix them:
Please see my answer or others that have use the same approach. But please be careful whenever you use some methods, always think about the complexity and the memory usage of your implementations.
This comment is hidden because it contains spoiler information about the solution
Also computationally inefficient, because each time an element gets evaluated, it is compared with all the existing lists. But I loved the functional approach.
Thanks :) I think it counts as a one-liner solution
Interesting answer
Interesting solution, yet it is very expensive in terms of space. You are creating a new list for every range, even if it is a one value range. So in worst case you would have n lists where n is the size of the array.
You're right, although String.repeat() was only added since Java 11 and won't work on java 8...
The bound + 1 / 2 is a nice trick that is useful in many situations where you need the same index for odd and even lengths.
Thank you very much for the explanation :)
Loading more items...