Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the method I cam up with in case it will help anyone.</p> <pre><code>// JavaScript Document var aInput = new Array(); aInput[0] = new Array("0", "1", "5"); aInput[1] = new Array("1", "1", "3"); aInput[2] = new Array("0", "10", "12"); aInput[3] = new Array("1", "10", "12"); var aOutput = []; console.log(ProcessArray(aInput)); function ProcessArray(aInput){ var input_indexed = [], elem = []; // elem holds the row to be added to the output // Get aInput[] into a more useful arrangement for (var i = 0; i &lt; aInput.length; i++) { // if set is complete process it if (i &gt; 0 &amp;&amp; parseInt(aInput[i][0]) == 0 &amp;&amp; parseInt(aInput[i-1][0]) &gt; 0){ aOutput = aOutput.concat(calcOutput(elem, input_indexed)); // clear set elem = []; input_indexed =[]; } // if fist set is not there then create it input_indexed[parseInt(aInput[i][0])] = { start: parseInt(aInput[i][1]), end: parseInt(aInput[i][2]) }; // Initialize elem with the start value of each column elem.push(parseInt(aInput[i][1])); } // reset elem with the start value of each column aOutput = aOutput.concat(calcOutput(elem, input_indexed)); return aOutput; } function calcOutput(elem, input_indexed){ // Produce the output var aReturn = []; done = false; while (!done) { aReturn.push(elem.slice(0)); // push a copy of elem into result for (i = elem.length - 1;; i--) { // Increment elements from right to left if (i == -1) { // We've run out of columns done = true; break; } elem[i]++; // Increment the current column if (elem[i] &lt;= input_indexed[i].end) { // If it doesn't overflow, we're done break; } // When it overflows, return to start value and loop around to next column elem[i] = input_indexed[i].start; } } return aReturn; } </code></pre>
 

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