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 how minimalistic this looks. Very clever. Though it's not for other word combinations as stated below, it's still very clever! Nice going.
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.
I really like the simplistic clarity of this solution. Thanks!
Why repeated sentence words are not all modified when .replace is used? Shouldn't .replace do that by definition?
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.
if sentence has more than one same word ,it will be wrong