Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will split your array into 2 arrays:</p> <pre><code>var articles = ["article1", "article2", "article3", "article4", "article5", "article6", "article7", "article8", "article9", "article10"]; var separatorIndex = articles.length &amp; 0x1 ? (articles.length+1)/2 : articles.length/2; var firstChunk = articles.slice(0,separatorIndex); //["article1", "article2", "article3", "article4", "article5"] var secondChunk = articles.slice(separatorIndex,articles.length); //["article6", "article7", "article8", "article9", "article10"] </code></pre> <p>Then you can use them where and/or how you want.</p> <p><em>Explanation</em></p> <p>The 2nd line finds an <em>anchor index</em> (alias -> middle index of division),by which array should be divided into 2 chunks. The array can have <code>odd</code> and <code>even</code> lengths,and those 2 situations must be distinguished. As it is impossible to divide odd-length array into 2 <em>equal</em> parts, it must be divided in such way, that 1st chunk will have 1 element <em>more</em> or <em>less</em>,than 2nd chunk.Here, I have implemented first case,that is, 1st chunk will have 1 element more,than 2nd one. Here are the examples of different situations:</p> <pre><code>total length | 1st (length) | 2st (length) | separatorIndex 10 0-4 (5) 5-9 (5) 5 11 0-5 (6) 6-10 (5) 6 12 0-5 (6) 0-11 (6) 6 </code></pre> <p>In table, <em><code>number</code>-<code>number</code></em> syntax shows accordingly start and end indexes in array. The division is done by <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/slice" rel="nofollow">.slice()</a> function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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