I have an array of array called 'data' which is:
(built it to adjust to use sb's advice on Active Admin)
I need to use its data to create a array of hash with this structure:
data_prepared_for_table = [{goal: data[0][0], number: data[0][1]},
{goal: data[1][0], number: data[1][1]},
{goal: data[2][0], number: data[2][1]},
{goal: data[3][0], number: data[3][1]},
{goal: data[4][0], number: data[4][1]},
{goal: data[5][0], number: data[5][1]}
]
in data_prepared_for_table, Goal has to display the first part of the array 'date': acquisition, branding, qualification.
Number has to display the related quantities in the array 'data' such as 3 , 2, 1.
I'd like to do 2 things:
streamline/improve the code by using a lop each or for, that would enable me to generate data_prepared_for_table something like:
data_prepared_for_table = [(0..5).each do |i| {goal: data[i][0], number: data[i][1]}, ]But it doesn't work and creates an error. How should I do it?
another thing is that in the example I give it goes up to data [5][0] but I want to be able to not specify the end (5 here) in case the array get longer and goes up to data [6] or even more [7] , and so on... I actually don't know in advance how long it will get!
How can I do it without specifying the last value of i? Maybe in the iteration, specify that i has to increment until data[i][0].exists??