Ad
  • Default User Avatar

    Arghh.. Thanks. I have updated the test cases. I missed it because even as arguments solution returns true. Rectified.

  • Custom User Avatar

    Ah, good point. The comment has been fixed. Thank you!

    I'm impressed at the success rate despite my difficulty describing the kata. =)

  • Default User Avatar

    Thanks much!! Got it working : ) The way it works seems a little awkward to me but it's working : ) so what happens in this example if we remove 8? will it then become something like (if i didn't make any mistake while copy-pasting) {value:4,left:{value:2,left:{value:1,left:{},right{}},right{value:3,left:{},right{}}},right{value:12,left:{value:10,left:{value:9,left:{},right{}},right{value:11,left:{},right{}}},right{value:14,left:{value:13,left:{},right{}},right{value:15,left:{},right{}}}}}?

  • Default User Avatar

    i really thought i had figured this out. i'm also passing all tests except for one, the "Share either 5's subtree or 7's subtree" test.

    I don't get it, I tested the following:

        mt = new EmptyBinaryTree;
        t1 = mt.insert(8).insert(4).insert(2).insert(1).insert(3).insert(6).insert(5).insert(7).insert(12).insert(10).insert(9).insert(11).insert(14).insert(13).insert(15);
        t2 = t1.remove(6);
        print(t1.left.right.left == t2.left.right)     
        print(t1.left.right.left === t2.left.right) 
        print(t1.left.left === t2.left.left) 
        print(t1.right === t2.right)
    

    All of those print "true", which makes me think that I am sharing all that I can including the 5's subtree. Any clue to what I could be doing wrong? In any case, this has been pretty neat.

  • Custom User Avatar

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

  • Custom User Avatar

    That's a great suggestion! I will have to ponder on how I can test operators are not eagerly evaluated in the solutions for this Kata. Let me think about it and I will see if I can improve the tests later today.

  • Custom User Avatar

    The typical approach in such situations is to move a node into the new spot. Go right one and left the whole way to the bottom (or left once and right to the bottom) and put that node in the vacated spot. In those scenarios, you can keep the left (or right) tree untouched. In that test, after removing 6, either the subtree containing 5 or the one containing 7 should be untouched.