Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>while-- is the way to go</p> <pre><code>var a=[],b=10;while(b--)a[b]=b+1 </code></pre> <p>returns [1,2,3,4,5,6,7,8,9,10]</p> <p>explained with start &amp; length</p> <pre><code>var array=[],length=20,start=5;while(length--)array[length]=length+start </code></pre> <p>returns [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] </p> <p>want range?</p> <p>explained with start &amp; end</p> <pre><code>var array=[],end=30,start=25,a=end-start+1;while(a--)array[a]=end-- </code></pre> <p>returns [25, 26, 27, 28, 29, 30]</p> <p>for --</p> <pre><code>for(var a=[],b=20;b&gt;0;b--,a[b]=b+1) </code></pre> <p>for++</p> <pre><code>for(var a=[],b=0;b&lt;20;b++,a[b]=b+1) </code></pre> <p>WHY is this theway to go?</p> <ol> <li><p>while -- is prolly the fastest loop;</p></li> <li><p>direct setting is faster than push &amp; concat;</p></li> <li><p>[] is also faster than new Array(10);</p></li> <li><p>it's not much longer code than all the others</p></li> </ol> <p>byte saving techniques:</p> <ol> <li>use the arguments as a placholder forthe in function variables</li> <li>don't use new Array(),push(),concat() if not needed</li> <li>place "(){};," only when needed.</li> <li>use a,b,c,d... in short functions.</li> </ol> <p>so if u want a function for this</p> <p>with start,end (range)</p> <pre><code>function range(a,b,c,d){d=[];c=b-a+1;while(c--)d[c]=b--;return d} </code></pre> <p>so now range(3,7) returns [3,4,5,6,7]</p> <p>u save bytes in many ways here and this function is also very fast as it does not use concat, push, new Array and it's made with a while --</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload