Ad
  • Default User Avatar
  • Default User Avatar

    You're absolutely right! I honestly have no idea why I did that, I was probably trying to avoid adding an extra line of code, but I should've been consistent about either modifying the existing structure or leaving it intact and creating all new objects. I can't really think of a way to accomplish the latter that's as concise as your suggestion though, as the guard body would need to be much more complex.

    Thanks for the feedback!

  • Custom User Avatar

    Amazing and clever solution! :) but wouldn't it make sense to split last line to:

    a.next = sortedMerge(first: a.next, second: b)
    return a

    Otherwise you are creating new instances of nodes as long as "first" and "second" aren't nil and as soon as one of them is nil you are recyling the old nodes.

    Anyway, best solution for this kata!