Ad
  • Default User Avatar

    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.

  • Custom User Avatar

    and what about words containing each others? That will be wrong too:

    "on the border of borderland"  ->  "on the redrob of redrobland"
    
  • Default User Avatar

    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.

  • Default User Avatar

    spoiler flags, damn you! x)