title: creating new arrays based on and ordered by one original array in javascript
body: <p>I am writing javascript to try to do only a few simple tasks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var series = ["A","0","0","B","0","C","0","0","D","0"];
  var off = 1;
  var built = 1;
  var position = 1;
  var masterSeries = [];
  var slot = 1;
  
  console.log(series);
  
  function createMaster() {
      for (var i = 0; i &lt;= series.length - 1; ++i) {
          masterSeries[i] = ["Mode" + off];
          //console.log("Creating Internal Array #" + off);
          off++
      }
      off = 1;
      //since we already have first series we just assign it here
      masterSeries[0] = series;
      return masterSeries;
  }
  
  function buildAltSeriesNoNull() {
      for (var i = 1; i &lt;= series.length - 1; i++) {
          slot++;
          console.log("Checking Slot: " + slot); 
          if (series[i] != "0") {
              console.log("Found Non Null, building: " + built);
              //code to mutate the original array into new arrays goes here
              var temp = series;
              var back = temp.slice(i, series.length);
              var front = temp.slice(0,i);
              var newline = back.concat(front);
              masterSeries[position] = newline;
              position++;
     console.log("Added to Master Series Mini Array:" + position);
              built++;
              
          } else {
              console.log("Skipping Slot: " + slot);
              
          }
          off++;
          //masterSeries[i] = ["Love" + numOffset];  //set the mode
      }
  console.log(masterSeries);
  }
  console.log(createMaster()); //Create the MasterSeries Display the Banks
  console.log("Memory banks have been created, and we have a valid series of numbers to work with!");
  console.log('\n');
  console.log(buildAltSeriesNoNull());</code></pre>
  </div>
  </div>
  </p>
  
  <ol>
  <li>I have an hard coded array of 10 index's that hold possible letters</li>
  <li>there will be a random amount of letters populating the 10 slots, it should not matter if the first index is null or not null</li>
  </ol>
  
  <p>For Example</p>
  
  <blockquote>
    <p>A00B0C00D0</p>
    
    <p>ABC00D00EF</p>
    
    <p>0A0B0C0D0E</p>
  </blockquote>
  
  <ol start="3">
  <li>The zero's should be treated as null (will come in handy in a second)</li>
  <li><p>First I want the program to iterate through each index after the first and </p>
  
  <p>A. determine if it is a null or a valid letter </p>
  
  <p>B. If it is null, then skip to next index </p>
  
  <p>C. If it has a valid letter than it will create a new array and 'resort' the original array into a custom sorted array that looks like this. (using one of the example original arrays above)</p></li>
  </ol>
  
  <p>ORIGINAL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->A00B0C00D0</p>
  </blockquote>
  
  <p>Program checks index 2, and it is null, move to next, checks index 3 it is null, move to next. Index 4 has a value, "<code>B</code>" So now program creates a new array simply called <code>array2nditerate</code> and the array now looks like this</p>
  
  <p>SECOND ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->B0C00D0A00</p>
  </blockquote>
  
  <p>THIRD ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->C00D0A00B0</p>
  </blockquote>
  
  <p>FOURTH ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->D0A00B0C00</p>
  </blockquote>
  
  <p>So it is creating a new array for each unique letter based on the position in the original array it sat.</p>
  
  <p>So once It creates all the unique sorted arrays for each slot that had a value. I would then need it to do the entire same process but this time to the positions in the original array that had null values only...so for example it would look like this.</p>
  
  <p>ORIGINAL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9] </p>
    
    <p>Value-->A00B0C00D0</p>
  </blockquote>
  
  <p>FIRST NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->00B0C00D0A</p>
  </blockquote>
  
  <p>SECOND NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->0B0C00D0A0</p>
  </blockquote>
  
  <p>THIRD NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->0C00D0A00B</p>
  </blockquote>
  
  <p>FOURTH NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->00D0A00B0C</p>
  </blockquote>
  
  <p>FIFTH NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->0D0A00B0C0</p>
  </blockquote>
  
  <p>SIXTH NULL ARRAY</p>
  
  <blockquote>
    <p>index-->[0,1,2,3,4,5,6,7,8,9]</p>
    
    <p>Value-->0A00B0C00D</p>
  </blockquote>
  
  <p>If you notice it created 4 Non Null Arrays custom sorted because there were only 4 letters in the array of 10 possible index positions. it created six non nulls because 10 positions -4 non null arrays is 6 null arrays</p>
  
  <p>I am not sure as to which method is quicker, better. Iterating with one for loop and sorting out into a pile of null arrays and sorting into a pile of non null arrays, or writing two separate functions that iterate</p>
  
  <ol>
  <li>once through looking only for non null index's and sorting that way</li>
  <li>sorting through looking for null index's and sorting that way</li>
  </ol>