I need to generate 2D array in rails from a set of given strings. For example:
days =[ "Monday",
"Tuesday",
"Wednesday",
]
Now I want to create a 2D array and the data in this array will be fill by using days string in random manner.
Example:
[monday, tuesday, wednesday],
[tuesday, wednesday, monday]
...
and so on depends on given dimensions
How to do it?
Edit
I tried this
# global variable
@@test_array = %w(:sunday :monday :tuesday)
def get_data(row, col)
@data_field = @@test_array.permutation.to_a(col)
return @data_field.slice!(row)
If I pass row:1 and col:1 It is working but If i pass a big number like 20 in rows and column it is storing null in database.
Edit-2
days = ["monday, "tuesday"]
rows = 3
col = 3
It should return (one of the possible solution due to random generation)
[[monday, tuesday, monday],[tuesday, monday, tuesday], [monday, monday, tuesday]]