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.
That method is okay for multiple instance of the same word but it makes a lot of sense that it's not for words containing each other and not for words with their reversals. Thanks for this reminder.
and what about words containing each others? That will be wrong too:
That isn't true, it works in that case because replace replaces all instances of the word on each call, but the foreach loop has the unmodified members of the array created using split.
The real issue is if there are words that also contain their reversals inside of the array. For example,
"12345 54321 12345"
produces
"54321 54321 54321"
because of how replace searches the entire string for all instances of the CharSequence to change, while the foreach loop will have the old data.
spoiler flags, damn you! x)