开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜