More efficient comparison of numbers
<p>I have an array which is part of a small JS game I am working on I need to check (as often as reasonable) that each of the elements in the array haven't left the "stage" or "playground", so I can remove them and save the script load</p>

<p>I have coded the below and was wondering if anyone knew a faster/more efficient way to calculate this. This is run every 50ms (it deals with the movement).</p>

<p>Where <code>bots[i][1]</code> is movement in X and <code>bots[i][2]</code> is movement in Y (mutually exclusive).</p>

<pre><code>for (var i in bots) {
    var left = parseInt($("#" + i).css("left"));
    var top = parseInt($("#" + i).css("top"));
    var nextleft = left + bots[i][1];
    var nexttop = top + bots[i][2];
    if(bots[i][1]&gt;0&amp;&amp;nextleft&gt;=PLAYGROUND_WIDTH) { remove_bot(i); }
    else if(bots[i][1]&lt;0&amp;&amp;nextleft&lt;=-GRID_SIZE) { remove_bot(i); }
    else if(bots[i][2]&gt;0&amp;&amp;nexttop&gt;=PLAYGROUND_HEIGHT) { remove_bot(i); }
    else if(bots[i][2]&lt;0&amp;&amp;nexttop&lt;=-GRID_SIZE) { remove_bot(i); }
    else {
        //alert(nextleft + ":" + nexttop);
        $("#" + i).css("left", ""+(nextleft)+"px");
        $("#" + i).css("top", ""+(nexttop)+"px");
    }
}
</code></pre>

<p>On a similar note the remove_bot(i); function is as below, is this correct (I can't splice as it changes all the ID's of the elements in the array.</p>

<pre><code>function remove_bot(i) {
    $("#" + i).remove();
    bots[i] = false;
}
</code></pre>

<p>Many thanks for any advice given!</p>
