title: JavaScript - Greatest common divisor - stuck in infinite loop
body: <p>I am writing a function to computer the greatest common divisor for multiple numbers and I am stuck in this infinite while loop:</p>
  
  <pre><code>const gcd = (...nums) =&gt; {
      let answer = Math.min.apply(null, nums);
      while (answer &gt; 0) {
          for (let index in nums) {
              if (nums[index] % answer !== 0) {
                  answer--;
                  break;
              } else if (index === (nums.length-1)){
                 return answer;
              }
          }
      }
  }
  
  gcd(20, 155, 30)
  </code></pre>
  
  <p>For my test case on the last line, I was able to get to 5, which is the correct answer. But it seems like once the answer gets to 5,  I am not able to get to the if nor the else if statement and I am stuck in the infinite while loop.</p>
  
  <p>Any pointers? </p>