title: JS maximum call stack exceeded
body: <p>I have this:</p>
  
  <pre><code>var Utilities = (function (array, maxN) {
  
    function generateRandomNumber(array, maxN) {
          let randomN = Math.floor(Math.random() * maxN) + 0;
  
          if(!array.includes(randomN)) {
              console.log(maxN);
              if(array.length == maxN) {
                  console.log('max reached');
                  array.length = 0;
                  return;
              }
              else {
                  array.push(randomN);
              }
  
          }
          else {
              randomN = generateRandomNumber(array, maxN);
          }
          return randomN;
      }
  
      return {
          generateRandomNumber: generateRandomNumber
      };
  
  })();
  
  export default Utilities;
  </code></pre>
  
  <p>and it's used like this on click:</p>
  
  <pre><code>function getRandomNumber(arr) {
      let randomN = Utilities.generateRandomNumber(arr, 5);
      return randomN;
  }
  </code></pre>
  
  <p>however, when the length of 5 is reached I get: (although I am clearing the array)
  I am trying to generate a random number however I don't want to repeat it, so I store it inside a an array to check if it has been generated already. However the issue I have is that (even though I am clearing the array once the length is = to max number) I get the "error" attached </p>
  
  <p><a href="https://i.stack.imgur.com/tgmgm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tgmgm.png" alt="enter image description here"></a></p>