Ad
  • Custom User Avatar

    Checking if the string length is odd is an obvious disqualifier that I didn't think to check for. Good call!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I disagree with your "really bad solution" comment and encourage anyone interested in learning more about processing data with functional programming to read Martin Fowler's Refactoring to Collection Pipelines

    A similar multi-stage pipeline approach is covered in the above article where Fowler refactors a loop that does multiple things in one pass into separate loops that each process the content with a different purpose. Fowler's article hits a number of different languages including c#, java and in this section, Ruby. In this section, he's quite clear with the section where he does this he introduces with the following:

    The biggest smell for me in this routine is that the loop is doing two things at once.

    Although he is using his "split loop" refactoring here, he ultimately transforms those loops into list processing functional programming calls. My point in citing his article is that he not only calls a loop that is doing multiple things at once a smell, it is the biggest smell for him in the code he is refactoring.

  • Default User Avatar

    A fair comment. The longer the string, the more time is saved by checking for these easy cases upfront.