title: Javascript Split Array
body: <p>I am trying to write a custom string splitting function, and it is harder than I would have expected.</p>
  
  <p>Basically, I pass in a string and an array of the values that the string will split on, and it will return an array of substrings, removing empty ones and including the values it splits on. If the string can be split at the same place by two different values, the longer one has precedence.</p>
  
  <p>That is,</p>
  
  <pre><code>split("Go ye away, I want some peace &amp;&amp; quiet. &amp; Thanks.", ["Go ", ",", "&amp;&amp;", "&amp;", "."]);
  </code></pre>
  
  <p>should return</p>
  
  <pre><code>["Go ", "ye away", ",", " I want some peace ", "&amp;&amp;", " quiet", ".", " ", "&amp;", " Thanks", "."]
  </code></pre>
  
  <p>Can you think of a reasonably simple algorithm for this? If there is a built-in way to do this in Javascript (I don't think there is), it would be nicer.</p>