Ruby: nested array structures (many levels) transformed into one array
I 开发者_StackOverflow中文版have the following array structure:
[[a], [b, c, [d, e]]]
That could have many levels of nesting (defined in execution time)
I would like to transform it in:
[a], [b,c], [d, e], ...
I have not found a way that works for 100% of the cases.
Any suggestion?
Thank you,
Array#flatten should do the trick?
Yes, the output using flatten is
[a, c, d, e] (depending of the level of recursion you use in flatten)
In fact, that output worked for me, I was over complicating desiring the [ [a], [b,c], [d, e] ]
Never the less, could be interesting to know the process for that particular output.
精彩评论