title: Split array in the best possible way with multiple functions
body: <p>I am looking for an algorithm name, preferably a library that can take an array and split it between functions in the best way possible.
  I don't care about the complexity (it's for a very low data set).
  Recursive check would suffice.</p>
  <p>A nice example would be array:</p>
  <pre><code>const list = [{gender: &quot;female&quot;}, {gender: &quot;female&quot;}, {gender: &quot;female&quot;}, {gender: &quot;male&quot;}]
  </code></pre>
  <p>So if we run it with the special function</p>
  <pre><code>specialFunc(list, [(val) =&gt; val === 'female', (val) =&gt; val === 'male']);
  </code></pre>
  <p>We would be getting this</p>
  <pre><code>[
   [{gender: &quot;female&quot;}, {gender: &quot;female&quot;}, {gender: &quot;female&quot;}],
   [{gender: &quot;male&quot;}]
  ]
  </code></pre>
  <p>Because this is the best possible split we can get.</p>
  <p>However, if we run it by this function:</p>
  <pre><code>specialFunc(list, [(val) =&gt; !!val, (val) =&gt; val === 'male']);
  </code></pre>
  <p>I would be getting this:</p>
  <pre><code>[
   [{gender: &quot;female&quot;}, {gender: &quot;female&quot;}, {gender: &quot;female&quot;}],
   [{gender: &quot;male&quot;}]
  ]
  </code></pre>
  <p>&quot;the best way possible&quot; means that the number distance (of array length) between each array should be the lowest, and the number of records in each array should be the maximum possible.</p>
  <p>I have searched npmjs and github a lot but couldn't find anything.</p>
  <p>Thank you very very much!</p>