title: How do you merge certain items in a JavaScript array?
body: <p>Say you have the following array:</p>
  
  <pre><code>const ab = ['a', 'a', 'b', 'b', 'b', 'a', 'b', 'b', 'a'];
  </code></pre>
  
  <p>How would you change this array so that all the "b" items get grouped together, until you hit another "a".</p>
  
  <p>So the result of the above array would look like:</p>
  
  <pre><code>['a', 'a', 'bbb', 'a', 'bb', 'a'];
  </code></pre>
  
  <p>I'm trying to solve a problem with wrapping span tags around words that match a patter in a React app, but this is <em>essentially</em> my problem.</p>
  
  <p>I've been working at it for ages but can't come up with anything I'm happy with.</p>
  
  <p>Any ideas?</p>
  
  <p>Cheers.</p>