title: How to make my static function recursive? (ordered/forward combinations)
body: <p>I'm having trouble getting the logic right for a seemingly simple recursive function. (End-goal is wrapping text of varying length inside circles of varying sizes, loosely based on <a href="https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap#Minimum_raggedness" rel="nofollow noreferrer">Knuth's (Tex) algorithm</a>... I think I've just been staring at this too long.)</p>
  <p>I'm stuck changing my static function to a dynamic version, so I can <strong>list all possible combinations that <code>n</code> words can be split among any number of lines</strong> (array <code>L[]</code>).</p>
  <ul>
  <li><strong>Each line must contain at least 1 word</strong></li>
  <li>These are sentences, so order matters! (and we can assume <code>L.length &lt;= n &lt; 0</code>)</li>
  </ul>
  <hr />
  <p>For example, with <strong>5 words</strong> (0-4) going into <strong>3 lines</strong> (0-2), all 6 combinations are:</p>
  <pre><code> Line0  Line1  Line2 
     0      1    2+3+4 
     0     1+2    3+4  
     0    1+2+3    4   
    0+1     2     3+4  
    0+1    2+3     4   
   0+1+2    3      4   
  </code></pre>
  <p>...which I can get with a simple function of nested loops:</p>
  <pre><code>//for 3 lines (L[0] to L[2])
  const n=5; //number of words
  var L=[0], ret=[]; //always starts at word#0 on line#0
  for(L[1]=L[0]+1; L[1]&lt;n; L[1]++){            // line#1
    for(L[2]=L[1]+1; L[2]&lt;n; L[2]++){          // line#2
      ret.push( L );
    }
  }                    // returns array of combinations of the start word# for each line,
  console.log( ret );  // like: [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4]]  ✔️
  </code></pre>
  <p>This works (matching the example combinations above)... but is hardcoded for 3 lines only.</p>
  <p>So, I'm trying to rewrite this as a recursive function so the number of lines (and words) can change dynamically.</p>
  <p>Any help is appreciated.</p>