Javascript challenge - which basket contains the last apple?
<p>I'm presented with the following challenge question:</p>

<blockquote>
  <p>There are a circle of 100 baskets in a room; the baskets are numbered
  in sequence from 1 to 100 and each basket contains one apple. 
  Eventually, the apple in basket 1 will be removed but the apple in
  basket 2 will be skipped.  Then the apple in basket 3 will be removed.
  This will continue (moving around the circle, removing an apple from a
  basket, skipping the next) until only one apple in a basket remains.
  Write some code to determine in which basket the remaining apple is
  in.</p>
</blockquote>

<p>I concluded that basket 100 will contain the last apple and here's my code:</p>

<pre><code>     var allApples = [];
        var apples = [];
        var j = 0;
        var max = 100; 
        var o ='';
            while (j &lt; max) {
                o += ++j;
                allApples.push(j);
            }

            var apples = allApples.filter(function(val) {
                return 0 == val % 2;
            });
            while (apples.length &gt; 1) {
                for (i = 0; i &lt; apples.length; i += 2) {
                    apples.splice(i, 1);
                }
            }

            console.log(apples);
</code></pre>

<p>My question is: did I do this correctly?  What concerns me is the description of "a circle" of baskets.  I'm not sure this is relevant at all to how I code my solution.  And would the basket in which the remaining apple reside be one that would otherwise be skipped?</p>

<p>I hope someone can let me know if I answered this correctly, answered it partially correct or my answer is entirely wrong.  Thanks for the help.</p>
