title: Fix elements and recursion help to understand
body: <p>I'm doing a Dynamic Programming excercise about making combination for array n size with result of k numbers combination and stumble upon this solution, I'm trying to understand what <strong>end-i+1 &gt;= r-index</strong> is doing here can someone explain.</p>
  <p>is this to make the current index make combinations with the other remaining index, still how does that work</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> function combinationUtil(arr,data,start,end,index,r)
      {
          // Current combination is ready to be printed, print it
          if (index == r)
          {
              for (let j=0; j&lt;r; j++)
              {
                  document.write(data[j]+" ");
              }
              document.write("&lt;br&gt;")
          }
           
          // replace index with all possible elements. The condition
          // "end-i+1 &gt;= r-index" makes sure that including one element
          // at index will make a combination with remaining elements
          // at remaining positions
          for (let i=start; i&lt;=end &amp;&amp; end-i+1 &gt;= r-index; i++)
          {
              data[index] = arr[i];
              combinationUtil(arr, data, i+1, end, index+1, r);
          }
      }
       
      // The main function that prints all combinations of size r
      // in arr[] of size n. This function mainly uses combinationUtil()
      function printCombination(arr,n,r)
      {
          // A temporary array to store all combination one by one
          let data = new Array(r);
           
          // Print all combination using temporary array 'data[]'
          combinationUtil(arr, data, 0, n-1, 0, r);
      }</code></pre>
  </div>
  </div>
  </p>