title: Looping over numbers
body: <p>So this is the question that is given.</p>
  
  <p>You are in a room with a circle of 100 chairs.  The chairs are numbered sequentially from 1 to 100.</p>
  
  <p>At some point in time, the person in chair #1 will be asked to leave.  The person in chair #2 will be skipped, and the person in chair #3 will be asked to leave. This pattern of skipping one person and asking the next to leave will keep going around the circle until there is one person left, the survivor.</p>
  
  <p>And this is the answer I came up with. I believe this is the right answer, I've done it on paper about 10 times as well and came up with 74 every time.
  Is this a trick question or something? Because I'm not sure what to do from here.</p>
  
  <p>Here is the jsfiddle <a href="http://jsfiddle.net/cQUaH/" rel="nofollow">http://jsfiddle.net/cQUaH/</a></p>
  
  <pre><code>var console = {
      log : function(s) {
          document.body.innerHTML += s + "&lt;br&gt;";
      }
  };
  
  var chairArr = [];
  for (var i = 1; i &lt;= 100; i++){
      chairArr.push(i);
  }
  
  var j = 2;
  while(chairArr.length &gt; 1) {
      console.log('removing ' + chairArr[j]);
      chairArr.splice(j, 1);
      j++;
      if(j &gt;= chairArr.length) {
         console.log('--- Finished pass');
         console.log('--- Array state:');
         console.log(chairArr);
         j = (j == chairArr.length) ? 0 : 1;   
      } 
  }
  console.log('--- Final result: ' + chairArr); 
  //result 74
  </code></pre>