title: Split long words into equal-length pieces
body: <p>How can I use JavaScript to split extremely long words? I am not looking for a CSS solution like <code>word-break: break-all</code>. The goal is to insert spaces in long words to break them into smaller pieces. The solution should be as fast as possible, since it will be called thousands of times in a few seconds.</p>
  
  <p>Example how the solution should work:</p>
  
  <pre><code>splitString("This is an exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxample string.");
  =&gt; This is an exxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxample string.
  
  splitString("AnotherExammmmmmmmmmmpleeeeeeeeeeeeeeeee");
  =&gt; AnotherExammmmmm mmmmmpleeeeeee eeeeeeeeee
  </code></pre>
  
  <p>Any words that are too long are split with a space character.</p>
  
  <p>It would be even better if the resulting pieces were of roughly equal length.</p>