title: Binary Search Tree serialization formatting
body: <p>I have created a function to serialize a binary sort tree. I am traversing the tree in preorder, so <code>Root -&gt; Left -&gt; Right</code> and building a string recursively.</p>
  
  <pre><code>function serialize(root, str = '') {
      if (root !== undefined) {
          str += root.data + ', ' + serialize(root.left) + serialize(root.right);
          return str;
      } else {
          return '';
      }
  }
  </code></pre>
  
  <p>My output is <code>"8, 3, 1, 6, 4, 7, 10, 14, 13, "</code> and I am trying to figure out a way to remove the trailing <code>,</code> and <code>whitespace</code>.</p>