I need to create a multidimensional array from an array.
For example, let's say the initial array = [1,2,3,4,5,6]
I need a multidimensional array of
[ [1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5],[1,2,3,4,5,6] ]
I feel like this should be so easy, but I am stuck.
Here's what I have so far, which is wrong
def solution(a)
empty =[]
a.each do |x|
new_array = Array(x)
empty.push(new_array)
end
empty.reverse
end
and I've tried
def solution(a)
empty =[]
for i in 1..a.size
new_array = Array(a.pop)
empty.push(new_array)
end
empty.reverse
end
Anybody have a solution or suggestion?
EDIT: I realized that I never specified whether the array will consist of more than integers. For my purposes, I am looking for a solution that will accommodate integers or strings.