title: Maximum call stack size exceeded JS
body: <p>I'm trying to understand the concept of recursion and wanted to use it in my code (the getUniqueInt function):</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>var getRandomInt = function (min, max) {
    return Math.floor(Math.random() * (max - min)) + min;
  };
  
  var getChosenNumbers = function (min, max) {
    var chosenNumbers = [];
    for (var k = min; k &lt;= max; k++) {
      chosenNumbers.push(k);
    }
    return chosenNumbers;
  };
  
  var arrayOfNumbers = getChosenNumbers(1, 8);
  
  var getUniqueInt = function (min, max) {
    var uniqueNumber;
    var randomNumber = getRandomInt(min, max);
    if (arrayOfNumbers.indexOf(randomNumber) !== -1) {
      uniqueNumber = randomNumber;
      arrayOfNumbers.splice(arrayOfNumbers.indexOf(uniqueNumber), 1);
    } else {
      uniqueNumber = getUniqueInt(min, max);
    }
    return uniqueNumber;
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>But I end up getting this:
  Uncaught RangeError: Maximum call stack size exceeded</p>
  
  <p>What am I doing wrong? And does my code (I mean the recursion part) make any sense or it's totally wrong?</p>