开发者

Ruby: nested array structures (many levels) transformed into one array

开发者 https://www.devze.com 2023-03-20 02:06 出处:网络
I 开发者_StackOverflow中文版have the following array structure: [[a], [b, c, [d, e]]] That could have many levels of nesting (defined in execution time)

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

精彩评论

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