Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with other posters about separating your logical and graphical view, but I'd like to answer your question as presented, as it should help you think about finding commonality in your code that you can factor out.</p> <p>When trying to automate the creation of a dataset like this, you need to look for commonalities and sequences. As you do that, you should be able to iterate towards a decent solution.</p> <p>For a start, rather than having a set of variables called xFile (where x is a-h), why not create an object called "Files", with properties a-h, thus:</p> <pre><code>files = { a:[], b:[], ... } </code></pre> <p>Even that may be more complex than you need - for ease of creation, you may find that you want a 2D array, where a=0, b=1 etc. is much easier to deal with (though see below, h=0, g=1... is even easier).</p> <p>So, the next obvious commonality is that the first cell in each of the arrays you present follows the same pattern: <code>[0+"%",0+((n/8)*100)+"%"]</code>, where <code>n</code> is 7->0 going from a-h. So you could easily generate each of the first cells thus:</p> <pre><code>files = []; for (i = 7; i &gt;= 0; i -= 1) { files[Math.abs(i-7)] = [0+"%",0+((i/8)*100)+"%"] } </code></pre> <p>Now, this is a little ugly, the Math.abs call there is because the numbers increase in the opposite direction to the array. There are other ways to do this, but IMO they are all pretty ugly. Instead, you could consider inverting the order of the array, so that it runs h-a, rather than a-h:</p> <pre><code>files = []; for (n = 0; n &lt;= 7; n += 1) { files[n] = [0+"%",0+((n/8)*100)+"%"] } </code></pre> <p>OK, so having seen this commonality, you can look at the next cells. These are all the same <code>[0+((1/8)*100)+"%",0+((n/8)*100)+"%"]</code> for the second, and <code>[0+((2/8)*100)+"%",0+((n/8)*100)+"%"]</code> for the third, both where where <code>n</code> is 0-7 for a-h. </p> <p>Actually, we see another commonality here:<br> They could both be described as <code>[0+((j/8)*100)+"%",0+((i/8)*100)+"%"]</code> where <code>i</code> is the <code>n</code> from before, and <code>j</code> is the rank (1-7).</p> <p>Even more, the difference between cell 0 and cells 1-7 is that cells 1-7 all start with <code>0+((i/8)*100)+</code>, whereas cell 0 just starts with <code>0+</code>. But what is <code>((0/8)*100)</code>? It's <code>0</code>! </p> <p>So, there are no special cases, each cell can be defined as <code>[0+((j/8)*100)+"%",0+((i/8)*100)+"%"]</code></p> <p>So, taking the loop from before, we can extend it with an inner loop, thus:</p> <pre><code>files = []; for (i = 0; i &lt;= 7; i += 1) { files[i] = [] for (j = 0; j &lt;=7; j += 1) { files[i][j] = [0+((j/8)*100)+"%",0+((i/8)*100)+"%"] } } </code></pre> <p>The above code is untested so I don't discount having made some error, but it <em>should</em> generate an array with the data you present above, (though running from h-a rather than a-h)</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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