title: How can I convert this large Javascript associative array into another form efficiently?
body: <p>I'm working on a data processing application, which after parsing through data, the data is organized as such in an associative array:</p>
  
  <pre><code>sensorNumber, timeOfReading, Count, Value
  2, 32242424, 2442, 42425.545545
  ...
  4, 4343435, 2442, 42425.545545
  ...
  </code></pre>
  
  <p>Its a pretty straightforward 4 column data structure, however it can get pretty large - up to 1 million rows in some extreme cases.</p>
  
  <p>Now, I would like to add all these data points in a chart that allows a zooming feature (which means no skipping points). </p>
  
  <p>The chart needs to separate each "sensorNumber" column data in separate series, in addition to that, it needs to further separate each "count" and "value" in additional sub-series.</p>
  
  <p>The most efficient chart data insertion method uses a data structure like the following:</p>
  
  <pre><code>time, Series1, Series2, Series3...
  </code></pre>
  
  <p>Basically all the "Y" values need to be added for each "X" value, this makes for faster insertion than plotting each X and Y at a time.</p>
  
  <p>Which means I need my data structure look like the following:</p>
  
  <p><strong>timeOfReading, Count(sensor#1), Value(sensor#1) ... Count(sensor#3),Value(sensor#3)...</strong></p>
  
  <p>Solution#1:</p>
  
  <p>1) sort all the rows by the "timeOfReading" attribute<br>
  2) create a new data structure and add columns for each "Count" and "Value" per sensor attribute to fill the row</p>
  
  <p>Solution#2:</p>
  
  <p>Use a dictionary, that stores arrays. Make each unique "timeOfReading" attribute a key, and create a multi-column array for each "count" and "sensor"</p>
  
  <p>Solution#2 seems a LOT more efficient since it does not need any sorting whatsoever. </p>
  
  <p>However, I'm wondering if there is an even more elegant solution to this that anybody could think of?</p>