I am extracting data from a database and storing it in two arrays, one array contains the labels for the data, and the other contains the data. I need to manipulate the arrays in a way so that I have one label for each set of data.
Arrays right now
labels – [Development, Development, Development, Development, Release, Release, Release, Release, ...]
data – [DevData1, DevData2, DevData3, DevData4, RelData1, RelData2, RelData3, RelData4, ...]
I only need only label per set of data, but I want to break the data into segments to correspond with the single labels. There are four label/data pairs because this is data from the last four months. I would just split the array on every 4th element, but some of the months dont have entries. So I need a better way to split the data.
Any ideas would be great.
Thanks.
You could combine the separate arrays into a hash without too much effort:
Just make sure you use
Hash.new { |h,k| h[k] = [ ] }and notHash.new([])or you’ll end up with two hash entries pointing at the same array and that will just make a mess of things.References:
each_with_indexpush