title: Writing a function which compares two trees and returns true if they are equal in structure and in value and false otherwise
body: <p>Given two trees, I want to return true if they are equal in structure and in value and false otherwise.</p>
  
  <p>Given the following class:</p>
  
  <pre><code>class TreeNode
    attr_accessor :val, :left, :right
  
    def initialize val, left = nil, right = nil
      @val = val
      @left = left
      @right = right
    end
  end
  </code></pre>
  
  <p>complete the function</p>
  
  <p><code>def binary_tree_compare(a, b)</code></p>
  
  <p>My research led me to <a href="https://stackoverflow.com/questions/7733986/2-binary-trees-are-equal-or-not">here</a>. I have tried the ruby solution but to no avail
  Below is the code I have tried so far:</p>
  
  <pre><code>def binary_tree_compare a, b
    for_check &lt;&lt; [a, b]   
  
    while a,b = for_check.shift  
      return false unless a.children.count == b.children.count 
      break if a.children.empty?
  
      a_children = a.children.sort 
      b_children = b.children.sort     
      return false unless a_children == b_children  
  
      0.upto(a_children.count - 1) do |i|
        for_check &lt;&lt; [a_children[i], b_children[i]]  
      end
    end
    return true
  end
  
  </code></pre>
  
  <h2>I expect the output to be true if TreeNodes a and b are equal in structure and in value and false otherwise.</h2>
  
  <p>I am getting a syntax error and this is the stack trace:</p>
  
  <pre><code>  solution.rb:4: syntax error, unexpected ',', expecting keyword_do_cond or ';' or '\n'
      while a,b = for_check.shift  
             ^
    solution.rb:12: syntax error, unexpected keyword_do_cond, expecting keyword_end
    ...0.upto(a_children.count - 1) do |i|
    ...                             ^~
    olution.rb:15: syntax error, unexpected keyword_end, expecting end-of-input
      end
      ^~~ ```
  </code></pre>