title: What is the time complexity of this for loop nested in a while loop?
body: <p>I am trying to optimize a function. I believe this nested for loop is quadratic, but I'm not positive. I have recreated the function below</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>const bucket = [["e","f"],[],["j"],[],["p","q"]]
  let totalLettersIWantBack = 4;
  
  //I'm starting at the end of the bucket
  function produceLetterArray(bucket, limit){
    let result = [];
    let countOfLettersAccumulated = 0;
    let i = bucket.length - 1;
      while(i &gt; 0){
        if(bucket[i].length &gt; 0){
          bucket[i].forEach( (letter) =&gt;{
          if(countOfLettersAccumulated === totalLettersIWantBack){
            return;
          }
          result.push(letter);
         countOfLettersAccumulated++;
          })
        }
        i--;
      }
    return result;
  }
  
  console.log(produceLetterArray(bucket, totalLettersIWantBack));</code></pre>
  </div>
  </div>
  </p>